首页 > 其他分享 >文本转语音

文本转语音

时间:2022-11-22 13:48:55浏览次数:36  
标签:SpeechSynthesis const 语音 SpeechSynthesisUtterance 设置 msg 文本

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); // 播放
}

 

标签:SpeechSynthesis,const,语音,SpeechSynthesisUtterance,设置,msg,文本
From: https://www.cnblogs.com/alannero/p/16914857.html

相关文章