kai*_*iro 2 javascript voice text-to-speech azure
我需要以下 JavaScript 的帮助,希望有人能帮助我。文本以英语语音朗读。
\n如何在以下工作代码中更改语言和语音?由于我的java技术较差,我在网上进行了大量搜索,但找不到合适的解决方案。
\n所以,不幸的是我的编程技能不够好,所以我需要一些具体代码的帮助。谢谢。
\n<!DOCTYPE html>\n<html lang="en">\n<head>\n <title>Microsoft Cognitive Services Speech SDK JavaScript Quickstart</title>\n <meta charset="utf-8" />\n</head>\n<body>\n \n <button id="startSpeakTextAsyncButton">speak</button>\n \n <!-- Speech SDK reference sdk. -->\n <script src="microsoft.cognitiveservices.speech.sdk.bundle.js"></script>\n\n <!-- Speech SDK Authorization token -->\n <script>\n var authorizationEndpoint = "token.php";\n\n function RequestAuthorizationToken() {\n if (authorizationEndpoint) {\n var a = new XMLHttpRequest();\n a.open("GET", authorizationEndpoint);\n a.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");\n a.send("");\n a.onload = function() {\n var token = JSON.parse(atob(this.responseText.split(".")[1]));\n serviceRegion.value = token.region;\n authorizationToken = this.responseText;\n subscriptionKey.disabled = true;\n }\n }\n }\n </script>\n\n <!-- Speech SDK USAGE -->\n <script>\n var startSpeakTextAsyncButton;\n var serviceRegion = "westeurope"; \n // for testing:\n // var voiceName = "HeddaRUS";\n // var voiceLanguage ="de-DE";\n\n var subscriptionKey;\n var authorizationToken;\n var SpeechSDK;\n var synthesizer; \n\n document.addEventListener("DOMContentLoaded", function () {\n startSpeakTextAsyncButton = document.getElementById("startSpeakTextAsyncButton");\n subscriptionKey = document.getElementById("subscriptionKey");\n \n startSpeakTextAsyncButton.addEventListener("click", function () {\n startSpeakTextAsyncButton.disabled = true;\n \n speechConfig = SpeechSDK.SpeechConfig.fromAuthorizationToken(authorizationToken, serviceRegion); \n \n // I don't know how the code should looke like:\n // speechConfig = SpeechSDK.SpeechConfig.setSpeechSynthesisLanguage(voiceLanguage);\n // speechConfig = SpeechSDK.SpeechConfig.setSpeechSynthesisVoiceName(voiceName);\n \n synthesizer = new SpeechSDK.SpeechSynthesizer(speechConfig);\n\n // output should be in German language: \n let inputText = "Ich m\xc3\xb6chte es auf deutsche Sprache setzen, wei\xc3\x9f aber nicht wie!";\n \n synthesizer.speakTextAsync(\n inputText,\n function (result) {\n startSpeakTextAsyncButton.disabled = false;\n window.console.log(result);\n synthesizer.close();\n synthesizer = undefined;\n });\n });\n\n if (!!window.SpeechSDK) {\n SpeechSDK = window.SpeechSDK;\n startSpeakTextAsyncButton.disabled = false;\n if (typeof RequestAuthorizationToken === "function") {RequestAuthorizationToken();}\n }\n });\n \n </script>\n</body>\n</html>\nRun Code Online (Sandbox Code Playgroud)\n
为了快速测试,您可以指定您的语言和语音,speechConfig如下所示:
<!DOCTYPE html>\n<html lang="en">\n<head>\n <title>Microsoft Cognitive Services Speech SDK JavaScript Quickstart</title>\n <meta charset="utf-8" />\n</head>\n<body>\n \n <button id="startSpeakTextAsyncButton" onclick="synthesizeSpeech()">speak</button>\n \n <!-- Speech SDK reference sdk. -->\n <script src="microsoft.cognitiveservices.speech.sdk.bundle.js"></script>\n \n <script>\n function synthesizeSpeech() {\n \n var speechConfig = SpeechSDK.SpeechConfig.fromSubscription("<your subscription key,you can find it on azure portal=> Kesy and Endpoints blade>", "<your region>");\n speechConfig.speechSynthesisVoiceName = "Microsoft Server Speech Text to Speech Voice (de-DE, Hedda)";\n speechConfig.speechSynthesisLanguage = "de-DE";\n \n \n var synthesizer = new SpeechSDK.SpeechSynthesizer(speechConfig);\n let inputText = "Ich m\xc3\xb6chte es auf deutsche Sprache setzen, wei\xc3\x9f aber nicht wie!";\n \n synthesizer.speakTextAsync(\n inputText,\n function (result) {\n startSpeakTextAsyncButton.disabled = false;\n window.console.log(result);\n synthesizer.close();\n synthesizer = undefined;\n });\n }\n \n </script>\n</body>\n</html>\nRun Code Online (Sandbox Code Playgroud)\n你可以从第130行找到这个页面上的所有语音名称。这不是你的错,似乎没有官方的js示例:(
\n| 归档时间: |
|
| 查看次数: |
1749 次 |
| 最近记录: |