You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Base information:
SDK version: 1.30.1
How to use the sdk: by script loader
Background:
How to know when the play of tts voice is end, i've tried the player.onAudioEnd hooks, that did not work. other methods can also be used as alternatives, i can not find any ways. you can see code comment —— NOT WORK
My Code:
/* eslint-disable */constload=require('load-script')constEventEmitter=require('eventemitter3')constSPEECH_KEY='my key XXX'constSPEECH_REGION='my region XXX'// load promisefunctionloadPromise(url){returnnewPromise((resolve,reject)=>{load(url,function(err,script){if(err){reject(err)}else{resolve(script)}})})}exportconstStatusTypes={CONNECTING: 'CONNECTING',OPEN: 'OPEN',SPEAKING: 'SPEAKING',CLOSING: 'CLOSING',CLOSED: 'CLOSED',}exportdefaultclassTextToSpeech{isSDKReady=falseSpeechSDK=nullspeaker=nullstatus=StatusTypes.CLOSEDconstructor(){this.initEventEmitter()this.initSDK()}initEventEmitter(){this.ee=newEventEmitter();}on(name,fn){this.ee.on(name,fn,{})}initSDK(){if(this.isSDKReady){return;}loadPromise('/azure-1.30.1/microsoft.cognitiveservices.speech.sdk.bundle-min.js').then((err,script)=>{this.isSDKReady=truethis.SpeechSDK=window.SpeechSDK})}createSpeaker(){if(!this.isSDKReady){return;}constspeechConfig=this.SpeechSDK.SpeechConfig.fromSubscription(SPEECH_KEY,SPEECH_REGION);// The language of the voice that speaks.speechConfig.speechSynthesisVoiceName="zh-CN-XiaoxiaoNeural";constplayer=newSpeechSDK.SpeakerAudioDestination();player.onAudioStart=function(_){debugger}player.onAudioEnd=function(_){debugger// NOT WORK};varaudioConfig=SpeechSDK.AudioConfig.fromSpeakerOutput(player);constsynthesizer=newthis.SpeechSDK.SpeechSynthesizer(speechConfig,audioConfig);returnsynthesizer}speak(text,cb){if(!this.speaker){this.speaker=this.createSpeaker()this.speaker.bookmarkReached=function(s,e){varstr=`BookmarkReached event: \ \r\n\tAudioOffset: ${(e.audioOffset+5000)/10000}ms \ \r\n\tText: \"${e.text}\".`;console.log(str);};this.speaker.synthesisCanceled=function(s,e){console.log("SynthesisCanceled event");};// NOT WORKthis.speaker.synthesisCompleted=function(s,e){varstr=`SynthesisCompleted event: \ \r\n\tAudioData: ${e.result.audioData.byteLength} bytes \ \r\n\tAudioDuration: ${e.result.audioDuration}`;console.log(str);};this.speaker.synthesisStarted=function(s,e){console.log("SynthesisStarted event");};this.speaker.synthesizing=function(s,e){varstr=`Synthesizing event: \ \r\n\tAudioData: ${e.result.audioData.byteLength} bytes`;console.log(str);};this.speaker.visemeReceived=function(s,e){varstr=`VisemeReceived event: \ \r\n\tAudioOffset: ${(e.audioOffset+5000)/10000}ms \ \r\n\tVisemeId: ${e.visemeId}`;console.log(str);};this.speaker.wordBoundary=function(s,e){// Word, Punctuation, or Sentencevarstr=`WordBoundary event: \ \r\n\tBoundaryType: ${e.boundaryType} \ \r\n\tAudioOffset: ${(e.audioOffset+5000)/10000}ms \ \r\n\tDuration: ${e.duration} \ \r\n\tText: \"${e.text}\" \ \r\n\tTextOffset: ${e.textOffset} \ \r\n\tWordLength: ${e.wordLength}`;console.log(str);};}if(this.status!==StatusTypes.SPEAKING){this.setStatus(StatusTypes.SPEAKING)this.ee.emit('status-change',this.status)}this.speaker.speakTextAsync("嗯,好的",(result)=>{if(result.reason==ResultReason.SynthesizingAudioCompleted){console.log("Speech synthesis completed");debugger;}else{console.log("Speech synthesis was cancelled. Error: "+result.errorDetails);}cb&&cb(this.speaker)},(err)=>{console.trace("err - "+err);cb&&cb(this.speaker)});}stop(){if(this.speaker){this.setStatus(StatusTypes.CLOSED)this.ee.emit('status-change',this.status)this.speaker.close()}}setStatus(status){this.status=status}}
The text was updated successfully, but these errors were encountered:
My solution: it helps the developers to know the timing of voice ending
constaudioBuffer=this.audioContext.createBuffer(1,audioData.length,22050)constbufferSource=this.bufferSource=this.audioContext.createBufferSource()bufferSource.buffer=audioBufferbufferSource.onended=event=>{emit('status','end')// any ways to emit the event are ok}
such code would help a lot, the developers may use it to synthesis many statements, once knowing the timing of statement complement, they will synthesis the next statement by producer-consumer model
Base information:
SDK version: 1.30.1
How to use the sdk: by script loader
Background:
How to know when the play of tts voice is end, i've tried the player.onAudioEnd hooks, that did not work. other methods can also be used as alternatives, i can not find any ways. you can see code comment —— NOT WORK
My Code:
The text was updated successfully, but these errors were encountered: