文本转语音
Web Speech API 有两个部分:SpeechSynthesis 语音合成 (文本到语音 TTS)和 SpeechRecognition 语音识别(异步语音识别)
SpeechSynthesis.cancel():移除所有语音队列中的谈话。
SpeechSynthesis.getVoices():返回当前设备所有可用声音的 SpeechSynthesisVoice列表。
SpeechSynthesis.pause():暂停状态。
SpeechSynthesis.resume():非暂停状态:如果已经暂停了则继续。
SpeechSynthesis.speak():添加一个utterance到语音谈话队列;它将会在其他语音谈话播放完之后播放。
SpeechSynthesisUtterance.lang:设置话语的语言。 例如:“zh-cn”表示中文
SpeechSynthesisUtterance.pitch:设置说话的音调(音高)。范围从0(最小)到2(最大)。默认值为1
SpeechSynthesisUtterance.rate:设置说话的速度。默认值是1,范围是0.1到10,表示语速的倍数,例如2表示正常语速的两倍
SpeechSynthesisUtterance.text:设置在说话时将合成的文本内容。
SpeechSynthesisUtterance.voice:设置用于说话的声音。
SpeechSynthesisUtterance.volume:设置将在其中发言的音量。区间范围是0到1,默认是1
上代码:
const synth = window.speechSynthesis; const msg = new SpeechSynthesisUtterance(); const speak = () => { window.speechSynthesis.cancel() msg.text = '危险,请小心驾驶'; // msg.lang = "zh-CN"; // 使用的语言:中文 msg.volume = 20; // 声音音量:1 msg.rate = 1; // 语速:1 msg.pitch = 0; // 音高:1 synth.speak(msg); // 播放 }
 
                    
                     
                    
                 
                    
                
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号