如何在浏览器中进行语音识别和文字转换语音声音?
网友回复
chrome的webkitSpeechRecognition可以实现,只是需要连接google服务器,示例代码:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta name="viewport" content="width=device-width"> <title>Speech color changer</title> <style> body, html { margin: 0; } html { height: 100%; } body { height: inherit; overflow: hidden; max-width: 800px; margin: 0 auto; } h1, p { font-family: sans-serif; text-align: center; padding: 20px; } div { height: 100px; overflow: auto; position: absolute; bottom: 0px; right: 0; left: 0; background-color: rgba(255,255,255,0.2); } ul { margin: 0; } .hints span { text-shadow: -1px 1px 0px rgb(254 254 254 / 90%); margin: 10px; display: block; height: 40px; line-height: 40px; cursor: pointer; } </style> </head> <body> <h1>用英文说出以下颜色</h1> <p>需要您的网络能够访问google提供的服务</p> <p class="hints"></p> <div> <p class="output"> <em>指令识别中.....</em> </p> </div> <script> // var SpeechRecognition = SpeechRecognition || webkitSpeechRecognition var SpeechGrammarList = SpeechGrammarList || webkitSpeechGrammarList var SpeechRecognitionEvent = SpeechRecognitionEvent || webkitSpeechRecognitionEven...
点击查看剩余70%
至于文字转语音也可以通过SpeechSynthesisUtterance实现,代码如下:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <script type="text/javascript"> var ssu = new SpeechSynthesisUtterance('加油南京'); // ssu.volume = 100 // 声音的音量 //ssu.rate = 1 // 语速,数值,默认值是1,范围是0.1到10 //ssu.pitch = 1.5 // 表示说话的音高,数值,范围从0(最小)到2(最大...
点击查看剩余70%