Browse Source

Merge commit '9b42e9f4006ab8cf92750155d1ab3ceefdc02ebf' into new_dev

weicu
lxm 1 year ago
parent
commit
8624ef2f1d
  1. 85
      lib/main.dart
  2. 26
      local_plugins/azure_speech/ios/azure_speech/Sources/tools/MicrophoneCapture.swift
  3. 16
      local_plugins/azure_speech/ios/azure_speech/Sources/tools/SimpleAudioReceiver.swift

85
lib/main.dart

@ -1,5 +1,8 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_intro/flutter_intro.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:get/get.dart';
import 'package:get_storage/get_storage.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
@ -108,27 +111,69 @@ class MainApp extends StatelessWidget {
Widget build(BuildContext context) {
// 在应用构建时立即初始化深链接处理
_initDeepLinkHandler();
// 获取保存的主题设置
final themeMode = ThemeService().getThemeMode();
// 使用 ScreenUtilInit 包装整个应用
return ScreenUtilInit(
designSize: const Size(375, 812), // 设计稿尺寸,根据你的设计稿调整
minTextAdapt: true,
splitScreenMode: true,
builder: (context, child) {
return GetMaterialApp(
title: 'VoiTrans',
theme: AppTheme.lightTheme,
darkTheme: AppTheme.darkTheme,
themeMode: ThemeService().getThemeMode(),
initialRoute: Routes.splash,
getPages: AppPages.pages,
initialBinding: InitialBinding(),
translations: AppTranslations(),
locale: Get.deviceLocale,
fallbackLocale: const Locale('en', 'US'),
debugShowCheckedModeBanner: false,
);
},
);
designSize: const Size(375, 812),
minTextAdapt: true,
splitScreenMode: true,
builder: (_, child) {
return GetMaterialApp(
title: 'Voitrans',
theme: AppTheme.lightTheme,
darkTheme: AppTheme.darkTheme,
themeMode: themeMode, // 使用提前获取的主题模式
initialBinding: InitialBinding(),
initialRoute: Routes.splash,
getPages: AppPages.pages,
debugShowCheckedModeBanner: false,
translations: AppTranslations(),
localizationsDelegates: const [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
locale: AppTranslations.deviceLocale(),
fallbackLocale: AppTranslations.getSmartFallbackLocale(),
supportedLocales: AppTranslations.supportedLocales,
builder: EasyLoading.init(
builder: (BuildContext context, Widget? widget) {
EasyLoading.instance.userInteractions = false;
return MediaQuery(
data: MediaQuery.of(context).copyWith(
textScaler: TextScaler.noScaling,
),
child: Intro(
padding: EdgeInsets.zero,
child: widget!,
),
);
},
),
);
});
// // 使用 ScreenUtilInit 包装整个应用
// return ScreenUtilInit(
// designSize: const Size(375, 812), // 设计稿尺寸,根据你的设计稿调整
// minTextAdapt: true,
// splitScreenMode: true,
// builder: (context, child) {
// return GetMaterialApp(
// title: 'VoiTrans',
// theme: AppTheme.lightTheme,
// darkTheme: AppTheme.darkTheme,
// themeMode: ThemeService().getThemeMode(),
// initialRoute: Routes.splash,
// getPages: AppPages.pages,
// initialBinding: InitialBinding(),
// translations: AppTranslations(),
// locale: Get.deviceLocale,
// fallbackLocale: const Locale('en', 'US'),
// debugShowCheckedModeBanner: false,
// );
// },
// );
}
}

26
local_plugins/azure_speech/ios/azure_speech/Sources/tools/MicrophoneCapture.swift

@ -444,6 +444,32 @@ public class MicrophoneCapture: NSObject {
// 安全地处理音频会话
guard let audioSession = audioSession else { return }
do {
try audioSession.setActive(false)
if self.hasBluetoothDevices {
print("耳机")
// 设置音频会话参数
try audioSession.setCategory(.playback,
mode: .videoChat,
options: [
.allowBluetoothA2DP,
.allowBluetooth
]) // 添加音频优先级控制
} else {
print("手机")
try audioSession.setCategory(.playback,
mode: .videoChat,
options: [
.mixWithOthers,
.defaultToSpeaker])
}
try audioSession.overrideOutputAudioPort(.none)
try audioSession.setActive(true)
} catch {
print("音频会话配置失败: \(error.localizedDescription)")
}
}

16
local_plugins/azure_speech/ios/azure_speech/Sources/tools/SimpleAudioReceiver.swift

@ -192,15 +192,13 @@ public class SimpleAudioReceiver: NSObject {
do {
// 确保正在写入状态
guard self._isWriting else { return }
// 设置音频会话参数
try audioSession.setCategory(.playAndRecord,
mode: .voiceChat,
options: [.defaultToSpeaker,
.mixWithOthers,
.defaultToSpeaker,
.allowBluetoothA2DP,
.allowBluetooth])
try audioSession.overrideOutputAudioPort(.none)
// 设置音频会话参数
try audioSession.setCategory(.playAndRecord,
mode: .videoChat,
options: [.allowBluetoothA2DP, // 允许蓝牙耳机,不占用hfp链路
.mixWithOthers,
.defaultToSpeaker]) // 添加音频优先级控制
try audioSession.setActive(true)
try micCapture.startCapture()
try micCapture.audioDataHandler = { data in

Loading…
Cancel
Save