javascript speech.synthesis.speak properties
javascript speech.synthesis.speak properties
我已经搜索了又搜索无济于事。至少从我找到的 API 中没有明确的文档。我想创建一个自定义对象,该对象可以保存此函数的属性并能够运行它
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()的按钮。代码有效,但我无法让它成为男性声音。我想用一种方法来调用它,如果有人有办法让它听起来很男性或知道这个文档,请发布这个,因为我希望其他搜索文档的人会找到你可爱的答案。
我也运行linux 15和chrome版本48。如果可能的话,我希望能够在其他浏览器上运行它。不过,让我们采取婴儿步骤。
最完整的文档位于 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>
相关文章:
- 在调用speak之前预加载Web Speech API
- javascript中对象构造函数中的var属性与this.properties
- 为什么是文档.旧版应用程序中的DOM-object.properties为null
- 定义this.properties或objectName.properties的javascript JSON对象
- How to declare a Map containing certain properties with flow
- javascript对象显示为null,但object.properties返回数据
- 如何在gsp页面上从javascript调用messages.properties(参数化)值
- 如何从catalina.properties获取值到jsp
- 在spring-boot中使用javascript在application.properties文件中获取值
- Javascript属性访问速度:var.properties与var[“属性”]的区别
- 在另一场胜利中获取Titanium.App.Properties或使其在全球范围内可用
- Sitecore SPEAK UI 以编程方式设置组合框的选定项
- emberjs Computed Properties
- 通过Web脚本的javascript控制器从Alfresco的alfresco-global.properties文件中
- javascript speech.synthesis.speak properties
- 如何在 Sitecore 中构建 SPEAK 组件
- Lis properties of CanvasRenderingContext2D
- Sitecore SPEAK - 以编程方式设置搜索数据源根目录
- 无法从struts.properties中读取某些字符串
- datatables column properties