我找了又找,都没有用。这个API没有明确的文档,至少在ive中是这样的。我想要创建一个自定义对象,它可以保存该函数的属性并能够运行它。
console.log(window.speechSynthesis.getVoices());
var voices = window.speechSynthesis.getVoices();
var kline = new Object();
kline.speakAloud = function(message) {
Speech = new SpeechSynthesisUtterance(message);
Speech.voice = voices[2];
Speech.gender = "male";
Speech.voiceURI = "Google UK English Male";
Speech.volume = 1; // 0 to 1
Speech.rate = 1; // 0.1 to 10
Speech.pitch = 2; //0 to 2
Speech.lang = 'en-GB';
window.speechSynthesis.speak(Speech);
};
kline.speakText = function(message) {
document.getElementById("Output").innerHTML = message;
};
//Arrays for Algorithmic Input Processing
var Greetings = ["hello", "hey", "hi", "sup"];
var Functions = ["say", "search", "math", "", "", "", "", ""];
function Run() {
message = document.getElementById("Input").value.toLowerCase();
console.log("Successfully ran function" + '\n' + "Input:" + document.getElementById("Input").value + '\n' + "Proccesed input:" + message);
//If statement
if (message === ("hello")) { // greating
kline.speakAloud("testing");
kline.speakText("testing");
}
else if (message === ("X")) { //
kline.speakAloud("");
kline.speakText("");
}
else if (message === ("X")) { //
kline.speakAloud("");
kline.speakText("");
}
else if (message === ("X")) { //
kline.speakAloud("");
kline.speakText("");
}
}
如果您需要html,我也可以发布它,它基本上是一个输入框和一个按钮来调用Run()。代码起作用了,但我不能让它成为男性的声音。我想用一种方法将它保存在同一个对象中,如果有人有办法使它听起来是男性的,或者知道它的文档,请发这个帖子,因为我希望其他搜索文档的人会找到你可爱的答案。
Im还运行linux 15和chrome版本48。如果可能的话,我希望能够在其他浏览器上运行这个功能。不过,让我们迈出一小步。
发布于 2016-02-12 14:35:03
最完整的文档在Web语音API规范中。
正如在这个答案中所描述的,只有在window.speechSynthesis.onvoiceschanged事件触发后才加载声音数组。如果将初始化代码移至此事件,则声音将可用。
var voices = []
var kline = new Object();
window.speechSynthesis.onvoiceschanged = function() {
voices = window.speechSynthesis.getVoices();
console.log(voices);
kline.speakAloud = function(message) {
Speech = new SpeechSynthesisUtterance(message);
Speech.voice = voices[2];
Speech.voiceURI = "Google UK English Male";
Speech.volume = 1; // 0 to 1
Speech.rate = 1; // 0.1 to 10
Speech.pitch = 0; //0 to 2
Speech.lang = 'en-GB';
window.speechSynthesis.speak(Speech);
};
kline.speakText = function(message) {
document.getElementById("Output").innerHTML = message;
};
};
//Arrays for Algorithmic Input Processing
var Greetings = ["hello", "hey", "hi", "sup"];
var Functions = ["say", "search", "math", "", "", "", "", ""];
function Run() {
message = document.getElementById("Input").value.toLowerCase();
console.log("Successfully ran function" + '\n' + "Input:" + document.getElementById("Input").value + '\n' + "Proccesed input:" + message);
//If statement
if (message === ("hello")) { // greating
kline.speakAloud("testing");
kline.speakText("testing");
}
else if (message === ("X")) { //
kline.speakAloud("");
kline.speakText("");
}
else if (message === ("X")) { //
kline.speakAloud("");
kline.speakText("");
}
else if (message === ("X")) { //
kline.speakAloud("");
kline.speakText("");
}
}<input type="text" id="Input" value="hello"/>
<input type="text" id="Output"/>
<button id="run" onclick="Run()">
Run
</button>
https://stackoverflow.com/questions/35354146
复制相似问题