Browse Source

Merge branch 'new_dev' of https://github.com/deepcloud2048/deep_voice into new_dev

newdev_shunjiawei
liwei1dao 1 year ago
parent
commit
aeeffb4037
  1. 131
      lib/modules/translation/views/translation_view.dart
  2. 21
      local_plugins/azure_speech/android/src/main/kotlin/com/yunqiinnovation/azure_speech/AzureAsrToAsr.kt
  3. 17
      local_plugins/azure_speech/ios/azure_speech/Sources/azure_speech/IntegratedSpeechTranslationService.swift

131
lib/modules/translation/views/translation_view.dart

@ -206,16 +206,35 @@ class TranslationView extends GetView<TranslationController> {
: Colors.grey[100], : Colors.grey[100],
borderRadius: BorderRadius.circular(16.r), borderRadius: BorderRadius.circular(16.r),
), ),
child: Obx(() => Text( child: Obx(() => Row(
'${controller.targetLanguage.value.split(' ')[0]}' mainAxisAlignment: MainAxisAlignment.center,
.tr, // Just show the English part children: [
style: TextStyle( Flexible(
fontSize: 16.sp, child: Text(
fontWeight: FontWeight.w600, '${controller.targetLanguage.value.split(' ')[0]}'
color: isDarkMode ? Colors.white : Colors.black, .tr,
), style: TextStyle(
textAlign: TextAlign.center, fontSize: 16.sp,
overflow: TextOverflow.ellipsis, fontWeight: FontWeight.w600,
color:
isDarkMode ? Colors.white : Colors.black,
),
textAlign: TextAlign.center,
overflow: TextOverflow.ellipsis,
),
),
//只在通话翻译模式下显示电话图标
if (controller.currentMode.value == 'call') ...[
SizedBox(width: 4.w),
Icon(
Icons.phone_in_talk,
size: 20.sp,
color: isDarkMode
? Colors.white70
: Colors.grey[600],
),
],
],
)), )),
), ),
), ),
@ -418,23 +437,27 @@ class TranslationView extends GetView<TranslationController> {
Row( Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
// 耳机图标按钮 (说话者1) // 耳机图标按钮 (说话者1)-显示源语言
_buildHoldToTalkButton( Obx(() => _buildHoldToTalkButton(
isDarkMode: isDarkMode, isDarkMode: isDarkMode,
speakerId: 1, speakerId: 1,
activeSpeaker: controller.activeSpeaker.value, activeSpeaker: controller.activeSpeaker.value,
icon: Icons.headset, icon: Icons.mic_none,
label: "headsetUser".tr, label: controller.sourceLanguage.value
), .split(' ')[0]
SizedBox(width: 40.w), .tr, // 源语言名称
// 手机图标按钮 (说话者2) )),
_buildHoldToTalkButton( SizedBox(width: 16.w),
isDarkMode: isDarkMode, // 手机图标按钮 (说话者2)-显示目标语言
speakerId: 2, Obx(() => _buildHoldToTalkButton(
activeSpeaker: controller.activeSpeaker.value, isDarkMode: isDarkMode,
icon: Icons.phone_android, speakerId: 2,
label: "phoneUser".tr, activeSpeaker: controller.activeSpeaker.value,
), icon: Icons.mic_none,
label: controller.targetLanguage.value
.split(' ')[0]
.tr, // 目标语言名称
)),
], ],
) )
else else
@ -569,15 +592,15 @@ class TranslationView extends GetView<TranslationController> {
}, },
child: AnimatedContainer( child: AnimatedContainer(
duration: const Duration(milliseconds: 200), duration: const Duration(milliseconds: 200),
width: 80.w, width: 160.w, // 长条形宽度
height: 80.w, height: 54.h, // 长条形高度
decoration: BoxDecoration( decoration: BoxDecoration(
color: isActive color: isActive
? (isDarkMode ? Colors.green[700] : Colors.green) ? (isDarkMode ? Colors.green[700] : Colors.green)
: (isDisabled : (isDisabled
? (isDarkMode ? Colors.grey[800] : Colors.grey[300]) ? (isDarkMode ? Colors.grey[800] : Colors.grey[300])
: (isDarkMode ? AppColors.primary : Colors.blue)), : (isDarkMode ? AppColors.primary : Colors.blue)),
shape: BoxShape.circle, borderRadius: BorderRadius.circular(25.r), // 圆角长条形
boxShadow: isActive boxShadow: isActive
? [ ? [
BoxShadow( BoxShadow(
@ -586,32 +609,42 @@ class TranslationView extends GetView<TranslationController> {
spreadRadius: 3, spreadRadius: 3,
) )
] ]
: null, : [
BoxShadow(
color: (isDarkMode ? Colors.black : Colors.grey)
.withOpacity(0.2),
blurRadius: 8,
spreadRadius: 1,
offset: Offset(0, 2),
)
],
), ),
child: Column( child: Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
Stack( // 左边图标
alignment: Alignment.center, Icon(
children: [ icon,
// 设备类型图标 color: isActive
Icon( ? Colors.white
icon, : Colors.white.withOpacity(isDisabled ? 0.3 : 0.9),
size: 20.sp,
),
SizedBox(width: 8.w), // 图标和文字间距
// 右边语言名称
Flexible(
child: Text(
label,
style: TextStyle(
fontSize: 12.sp,
fontWeight: FontWeight.w500,
color: isActive color: isActive
? Colors.white ? Colors.white
: Colors.white.withOpacity(isDisabled ? 0.3 : 0.9), : Colors.white.withOpacity(isDisabled ? 0.3 : 0.9),
size: 24.sp,
), ),
], textAlign: TextAlign.center,
), maxLines: 1,
SizedBox(height: 4.h), overflow: TextOverflow.ellipsis, // 防止文本溢出
Text(
label,
style: TextStyle(
fontSize: 12.sp,
color: isActive
? Colors.white
: Colors.white.withOpacity(isDisabled ? 0.3 : 0.9),
), ),
), ),
], ],

21
local_plugins/azure_speech/android/src/main/kotlin/com/yunqiinnovation/azure_speech/AzureAsrToAsr.kt

@ -328,10 +328,14 @@ class IntegratedSpeechTranslationService(
confidence confidence
) )
Log.d(TAG, "识别完成事件: ${event.result.text},serviceConfig.sourceLanguage:${serviceConfig.sourceLanguage}") Log.d(TAG, "识别完成事件: ${event.result.text},serviceConfig.sourceLanguage:${serviceConfig.sourceLanguage}")
// 触发翻译流程 // 只有在服务仍在运行时才触发翻译流程
launch { if (serviceState.isRecognizing.get()) {
Log.d(TAG, "触发翻译流程: ${event.result.text}") launch {
processTranslationAndSynthesis(event.result.text) Log.d(TAG, "触发翻译流程: ${event.result.text}")
processTranslationAndSynthesis(event.result.text)
}
} else {
Log.d(TAG, "服务已停止,跳过翻译流程: ${event.result.text}")
} }
} }
} }
@ -478,6 +482,7 @@ class IntegratedSpeechTranslationService(
recognizer?.stopContinuousRecognitionAsync() recognizer?.stopContinuousRecognitionAsync()
audioProcessor?.stopRecording() audioProcessor?.stopRecording()
recordfile1!!.closeFile(true) recordfile1!!.closeFile(true)
serviceState.isRecognizing.set(false)
// 等待当前处理完成 // 等待当前处理完成
while (serviceState.isTranslating.get() || serviceState.isSynthesizing.get()) { while (serviceState.isTranslating.get() || serviceState.isSynthesizing.get()) {
Thread.sleep(100) Thread.sleep(100)
@ -494,7 +499,13 @@ class IntegratedSpeechTranslationService(
* 处理翻译和合成流程 * 处理翻译和合成流程
*/ */
private suspend fun processTranslationAndSynthesis(text: String) { private suspend fun processTranslationAndSynthesis(text: String) {
Log.d(TAG, " 翻译状态:${serviceState.isTranslating.get()}") // 检查服务是否仍在运行
if (!serviceState.isRecognizing.get()) {
Log.d(TAG, "服务已停止,取消翻译流程: $text")
return
}
Log.d(TAG, " 翻译状态:${serviceState.isTranslating.get()}")
if (serviceState.isTranslating.get()) { if (serviceState.isTranslating.get()) {
Log.w(TAG, "翻译正在进行中,跳过当前请求") Log.w(TAG, "翻译正在进行中,跳过当前请求")
return return

17
local_plugins/azure_speech/ios/azure_speech/Sources/azure_speech/IntegratedSpeechTranslationService.swift

@ -388,9 +388,13 @@ import os.log
os_log("识别完成事件: %@", log: self.log, type: .info, text) os_log("识别完成事件: %@", log: self.log, type: .info, text)
// 触发翻译流程 // 检查服务状态,只有在识别仍然活跃时才触发翻译流程
Task { if self.serviceState.isRecognizing {
await self.processTranslationAndSynthesis(text: text) Task {
await self.processTranslationAndSynthesis(text: text)
}
} else {
os_log("服务已停止,跳过翻译流程", log: self.log, type: .info)
} }
} }
@ -593,6 +597,7 @@ import os.log
*/ */
public func stopContinuousTranslation() { public func stopContinuousTranslation() {
do { do {
self.serviceState.isRecognizing = false
try recognizer?.stopContinuousRecognition() try recognizer?.stopContinuousRecognition()
audioProcessor?.stopMicrophoneCapture() audioProcessor?.stopMicrophoneCapture()
recordFile?.closeFile(isSave: true) recordFile?.closeFile(isSave: true)
@ -614,6 +619,12 @@ import os.log
* 处理翻译和合成流程 * 处理翻译和合成流程
*/ */
private func processTranslationAndSynthesis(text: String) async { private func processTranslationAndSynthesis(text: String) async {
// 添加服务状态检查
guard serviceState.isRecognizing else {
os_log("服务已停止,取消翻译流程", log: log, type: .info)
return
}
os_log("翻译状态: %@", log: log, type: .debug, serviceState.isTranslating ? "进行中" : "空闲") os_log("翻译状态: %@", log: log, type: .debug, serviceState.isTranslating ? "进行中" : "空闲")
if serviceState.isTranslating { if serviceState.isTranslating {

Loading…
Cancel
Save