我正在尝试在我的应用程序中添加HMS自动语音识别(ASR)。我已经实现了SpeechRecognizer,但它需要GMS才能工作。
目前的HMS实现工作在一个安装了HMS核心的非华为设备上,但不工作在我的华为Mediapad T5上。
我试过的东西
这些方法是从不同的线程(主线程和图形线程)调用的,因此我尝试将锁上的方法同步或post将一个Runnable与活动处理程序同步,但没有造成太大的差别。也就是说,用synchronized(lock)或activity.post包装函数。
代码:
fun init(activity: Activity)speechRecognizer = MLAsrRecognizer.createAsrRecognizer(activity)
speechIntent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH)
.putExtra(
MLAsrCaptureConstants.LANGUAGE,
"en-US"
)
.putExtra(MLAsrConstants.FEATURE, MLAsrConstants.FEATURE_ALLINONE)
speechRecognizer?.setAsrListener(listener)fun startListening()speechRecognizer?.startRecognizing(speechIntent)fun destroy()speechRecognizer?.destroy()日志
4945-4945 W/HmsSpeechRecognitionHolder@c1cafe: init on Thread[main,5,main]
4945-4945 W/InputMethodManager: startInputReason = 1
4945-4945 W/HmsSpeechRecognitionHolder@c1cafe: startListening on Thread[main,5,main]
4945-4945 E/HaLogProvider: forbiddenHiLog openHa = false
4945-4945 E/HaLogProvider: forbiddenHiLog.getVenderCountry=ca
4945-4945 E/HaLogProvider: forbiddenHiLog openHa = false
4945-4945 E/MLASR_HaAdapter_MLKitAsr: mEventsToBeReported: has no response event isInfoGatherStart:falsemsg: 0
4945-4945 E/HwCustAudioRecordImpl: isOpenEC : false
634-985 E/HuaweiProcessing: ProcessingLib_Create: the algo have already been created.
634-985 W/EffectsFactory: EffectCreate() library huawei_processing: could not create fx Huawei Audio Preprocessing Effect, error -22
634-985 E/EffectFactoryHAL: Error creating effect e707d040-6b79-11e2-b16a-0002a5d5c51b: Invalid argument
721-8060 E/AudioEffect: set(): AudioFlinger could not create effect, status: -19
721-8060 W/AudioPolicyEffects: addInputEffects(): failed to create Fx huawei_pre_processing on source 1
634-8049 E/baidu_asr_interface: asr_baidu_set_parameters_data-not baidu asr
634-7993 W/DeviceHAL: Device 0x78c2d00000 get_mic_mute: Function not implemented
634-987 W/DeviceHAL: Device 0x78c2dc4680 get_mic_mute: Function not implemented
721-8009 W/HuaweiAudioFlinger: soundtrigger is now disable or not support, pls enable it first from setting
721-8009 W/APM_AudioPolicyManager: startInput(78) failed: other input 70 already started
721-8009 E/AudioFlinger: RecordThread::start error,setCallingAppName -1
4945-4945 E/AudioRecord: start() status -38
4945-4945 E/MLASR_A: getVendorCountry=ca
500-8480 W/libc: Set property "hw.wifi.dns_stat" to "99,14,14044,1,34759"
1472-1472 W/HwKeyguardDragHelper: AnimationBlocked
4945-5079 W/libEGL: EGLNativeWindowType 0x79e0317010 disconnect failed
1140-2290 E/WindowManager: win=Window{d80c651 u0 ProjectActivity} destroySurfaces: appStopped=true win.mWindowRemovalAllowed=false win.mRemoveOnExit=false
767-767 E/wificond: Failed to get NL80211_RATE_INFO_NOISE
767-767 E/wificond: Failed to get NL80211_RATE_INFO_SNR
767-767 E/wificond: Failed to get NL80211_STA_INFO_CNAHLOAD
1140-1316 E/WificondControl: Noise: 0, Snr: -1, Chload: -1
767-767 E/wificond: Failed to get NL80211_RATE_INFO_SNR
767-767 E/wificond: Failed to get NL80211_STA_INFO_CNAHLOAD
767-767 E/wificond: Failed to get NL80211_RATE_INFO_NOISE
767-767 E/wificond: Failed to get NL80211_RATE_INFO_SNR
767-767 E/wificond: Failed to get NL80211_STA_INFO_CNAHLOAD
1140-1316 E/WificondControl: Noise: 0, Snr: -1, Chload: -1
761-8466 W/ACodec: forcing OMX state to Idle when received shutdown in ExecutingState
769-8467 W/SimpleSoftOMXComponent: onChangeState mState= 3, mTargetState = 3, state = 2
769-8467 W/SimpleSoftOMXComponent: checkTransitions port buf count is not zero
769-1826 W/SimpleSoftOMXComponent: checkTransitions port buf count is not zero
769-1826 W/SimpleSoftOMXComponent: checkTransitions port buf count is not zero
769-1826 W/SimpleSoftOMXComponent: checkTransitions port buf count is not zero
769-1826 W/SimpleSoftOMXComponent: checkTransitions port buf count is not zero
769-1826 W/SimpleSoftOMXComponent: checkTransitions mState = 2, mTargetState = 1
721-8060 W/HuaweiAudioFlinger: soundtrigger is now disable or not support, pls enable it first from setting
1900-3437 E/HSM: BMNCaller:is not PermissionEnabled.
721-6695 W/AudioFlinger::EffectModule: EffectModule 0x7ba4f22a00 destructor called with unreleased interface
634-941 E/audio_hw_primary: in_remove_audio_effect error effect is null
634-941 W/StreamHAL: Error from HAL stream in function remove_audio_effect: Function not implemented
721-6695 E/AudioFlinger::EffectModule: Error when removing effect: -38
721-6695 W/AudioFlinger::EffectHandle: disconnect Effect handle 0x7ba4e45800 disconnected after thread destruction
1640-1796 W/AudioState: session release and not found sessionId: 81
4945-4945 W/HmsSpeechRecognitionHolder@c1cafe: destroy on Thread[main,5,main]
4945-8481 E/HwCustAudioRecordImpl: isOpenEC : false
4945-8481 E/HwCustAudioRecordImpl: isOpenEC : false我在日志里发现可疑的东西
634-985 E/HuaweiProcessing: ProcessingLib_Create: the algo have already been created.
634-985 W/EffectsFactory: EffectCreate() library huawei_processing: could not create fx Huawei Audio Preprocessing Effect, error -22
634-985 E/EffectFactoryHAL: Error creating effect e707d040-6b79-11e2-b16a-0002a5d5c51b: Invalid argument
721-8060 E/AudioEffect: set(): AudioFlinger could not create effect, status: -19
721-8060 W/AudioPolicyEffects: addInputEffects(): failed to create Fx huawei_pre_processing on source 1
721-8009 W/APM_AudioPolicyManager: startInput(78) failed: other input 70 already started
721-8009 E/AudioFlinger: RecordThread::start error,setCallingAppName -1
4945-4945 E/AudioRecord: start() status -38注意:我尝试过的 HMS演示应用程序在我的Mediapad T5上正确工作。
更新:在@shirley指出了一些修复之后,似乎正在可靠地工作在P30Lite上。但在老式的Mediapad T5上仍然面临着同样的问题。
发布于 2021-03-29 09:32:13
根据您提供的日志,无法检测到用户的声音。日志和状态代码的含义如下:


溶液

mSpeechRecognizer.destroy()。检查此方法是否被过早调用并在启动之前结束。在查看日志之后,会发现以下错误:

造成此错误的原因是:用于语音识别的Languagecode超过10。
您可以在这里查看代码:

确保语音识别语言不超过10。
11203 ,subError code: 3002,errorMessage: Service unavailable
造成此错误的原因是项目中找不到app_id信息。
建议您检查项目中是否存在agconnecn-services.json文件,如下所示


如果该文件不存在,则需要将其添加到项目中。如果文件存在,请确保app_id是正确的。
有关详细信息,请参阅以下文档。
onError(int error, String errorMessage)类的MLAsrListener方法获得原因,如下图所示。

可以将上述方法添加到侦听器的类中:

2.如果成功地启用了语音识别,但没有获得语音识别结果:
MLAsrConstants.FEATURE参数设置为FUNCTION_ALLINONE。因此,您需要在onResults(Bundle results)方法中获得语音识别结果,如下图所示。

发布于 2021-03-31 17:49:35
一些型号的手机和平板电脑在使用ML时可能存在资源限制问题。问题的症状是,在单击麦克风按钮后,电话/平板电脑没有响应,或者显示错误消息,指示设备上没有安装语音识别服务。不仅仅是HMS,我还尝试使用本地的Android SpeechRecognizer来实现语音识别,示例应用程序在点击有限硬件资源手机模拟器上的按钮后挂起。
为了解决您的问题,我建议使用HMS ML工具包ASR切换到使用HMS ML工具包实时转录(RTT)。RTT提供了与ASR类似的语音识别功能,并将语音转换为文本。有关更多细节,请参见ML试剂盒-实时转录 (huawei.com)上的HMS文档。
RTT的代码类似于ASR,您需要提供一个SpeechRecognitionListener类或匿名类来实现MLSpeechRealTimeTranscriptionListener。在文档链接中也有示例代码。我在我的华为手机伙伴30 Pro上测试了示例代码,它运行得很好。
https://stackoverflow.com/questions/66835800
复制相似问题