say
通过该函数,artyom 可以在 Google Chrome 中说话。
该函数允许用户将任何文本字串合成为声音。该函数接受两个参数,第一个参数是需要合成为声音的文本字串,而第二个参数则是回调函数的对象,第二个参数是可选的。
Parameters
type
Description
text
String
The string that's meant to be spoken
configuration
Object
An object with the 2 available callbacks for this function and the code language if you don't want to use the same language providen in the initialization.
onStart
: a function triggered when artyom starts to speak.onEnd
: a function triggered when artyom stops speaking.lang
: force the language for a single utterance object.
artyom.say
函数使用了Google Chrome 的原生 speechSynthesis API,同时内置了许多适配方法,以提供一种不受任何字符限制的干净实用的文本转语音方法。
Artyom消除了原始API功能中的字符限制。
Artyom保障了回调函数的执行(原生API中,这些时间有时候不会被触发)。
Artyom简化了API的调用方式,使其更容易使用。
在单词说话时强制使用某语种
默认情况下,say
函数使用初始化方法中提供的语种。但是也可以指定自定义语种说单条语言,通过函数的第二个参数进行设置即可。
重要! 在指定单句说话的语种之前需要提供一个初始化语种,否则可能会出现错误。
对于大型文本的推荐
Last updated
Was this helpful?