国外网站用什么dns好,建一个下载网站要什么cms系统,前端开发培训班学出来有用吗,自己创建小程序语音识别
需求#xff1a;
参考官方文档#xff0c;整合语音识别apicallback 的写法改为 Promise 的版本
在startRecord中#xff1a;
参考文档实例化-开启转换将录制的内容传递给录音识别回调函数中的 Log#xff0c;改为 Logger
在closeRecord#xff1a;
结束识别…语音识别
需求
参考官方文档整合语音识别apicallback 的写法改为 Promise 的版本
在startRecord中
参考文档实例化-开启转换将录制的内容传递给录音识别回调函数中的 Log改为 Logger
在closeRecord
结束识别、释放资源设置状态为 VoiceState.VOICEOVER async startRecord() {// 开始识别this.asrEngine await speechRecognizer.createEngine({language: zh-CN,online: 1})// 保存组件的 this后续通过_this来使用组件const _this thisthis.asrEngine.setListener({onStart(sessionId: string, eventMessage: string) {console.info(onStart, sessionId: ${sessionId} eventMessage: ${eventMessage});},onEvent(sessionId: string, eventCode: number, eventMessage: string) {console.info(onEvent, sessionId: ${sessionId} eventCode: ${eventCode} eventMessage: ${eventMessage});},onResult(sessionId: string, result: speechRecognizer.SpeechRecognitionResult) {_this.keyword result.result_this.onChange(result.result)console.info(onResult, sessionId: ${sessionId} sessionId: ${JSON.stringify(result)});},onComplete(sessionId: string, eventMessage: string) {_this.onComplete(_this.keyword)_this.keyword _this.voiceState VoiceState.DEFAULTconsole.info(onComplete, sessionId: ${sessionId} eventMessage: ${eventMessage});},onError(sessionId: string, errorCode: number, errorMessage: string) {console.error(onError, sessionId: ${sessionId} errorCode: ${errorCode} errorMessage: ${errorMessage});}})const recognizerParams: speechRecognizer.StartParams {sessionId: 10000,audioInfo: {audioType: pcm,sampleRate: 16000,soundChannel: 1,sampleBit: 16}}this.asrEngine?.startListening(recognizerParams)// 开始录音const audioStreamInfo: audio.AudioStreamInfo {samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_16000,channels: audio.AudioChannel.CHANNEL_1,sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE,encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW}const audioCapturerInfo: audio.AudioCapturerInfo {source: audio.SourceType.SOURCE_TYPE_MIC,capturerFlags: 0}const audioCapturerOptions: audio.AudioCapturerOptions {streamInfo: audioStreamInfo,capturerInfo: audioCapturerInfo}this.audioCapturer await audio.createAudioCapturer(audioCapturerOptions)this.audioCapturer.on(readData, (buffer) {console.log(mk-logger, buffer.byteLength)this.asrEngine?.writeAudio(10000, new Uint8Array(buffer))})await this.audioCapturer.start()this.voiceState VoiceState.VOICING}