Javascript Azure文本到语音:如何更改输出的语言和语音?
我需要以下JavaScript的帮助,希望有人能帮助我。文本以英语语音读出 如何在以下工作代码中更改语言和语音?我在网上进行了大量搜索,但由于java技能差,找不到合适的解决方案 所以,不幸的是,我的编程技能不够好,所以我需要一些具体代码行的帮助。谢谢Javascript Azure文本到语音:如何更改输出的语言和语音?,javascript,azure,text-to-speech,voice,Javascript,Azure,Text To Speech,Voice,我需要以下JavaScript的帮助,希望有人能帮助我。文本以英语语音读出 如何在以下工作代码中更改语言和语音?我在网上进行了大量搜索,但由于java技能差,找不到合适的解决方案 所以,不幸的是,我的编程技能不够好,所以我需要一些具体代码行的帮助。谢谢 <!DOCTYPE html> <html lang="en"> <head> <title>Microsoft Cognitive Services Speech SDK
<!DOCTYPE html>
<html lang="en">
<head>
<title>Microsoft Cognitive Services Speech SDK JavaScript Quickstart</title>
<meta charset="utf-8" />
</head>
<body>
<button id="startSpeakTextAsyncButton">speak</button>
<!-- Speech SDK reference sdk. -->
<script src="microsoft.cognitiveservices.speech.sdk.bundle.js"></script>
<!-- Speech SDK Authorization token -->
<script>
var authorizationEndpoint = "token.php";
function RequestAuthorizationToken() {
if (authorizationEndpoint) {
var a = new XMLHttpRequest();
a.open("GET", authorizationEndpoint);
a.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
a.send("");
a.onload = function() {
var token = JSON.parse(atob(this.responseText.split(".")[1]));
serviceRegion.value = token.region;
authorizationToken = this.responseText;
subscriptionKey.disabled = true;
}
}
}
</script>
<!-- Speech SDK USAGE -->
<script>
var startSpeakTextAsyncButton;
var serviceRegion = "westeurope";
// for testing:
// var voiceName = "HeddaRUS";
// var voiceLanguage ="de-DE";
var subscriptionKey;
var authorizationToken;
var SpeechSDK;
var synthesizer;
document.addEventListener("DOMContentLoaded", function () {
startSpeakTextAsyncButton = document.getElementById("startSpeakTextAsyncButton");
subscriptionKey = document.getElementById("subscriptionKey");
startSpeakTextAsyncButton.addEventListener("click", function () {
startSpeakTextAsyncButton.disabled = true;
speechConfig = SpeechSDK.SpeechConfig.fromAuthorizationToken(authorizationToken, serviceRegion);
// I don't know how the code should looke like:
// speechConfig = SpeechSDK.SpeechConfig.setSpeechSynthesisLanguage(voiceLanguage);
// speechConfig = SpeechSDK.SpeechConfig.setSpeechSynthesisVoiceName(voiceName);
synthesizer = new SpeechSDK.SpeechSynthesizer(speechConfig);
// output should be in German language:
let inputText = "Ich möchte es auf deutsche Sprache setzen, weiß aber nicht wie!";
synthesizer.speakTextAsync(
inputText,
function (result) {
startSpeakTextAsyncButton.disabled = false;
window.console.log(result);
synthesizer.close();
synthesizer = undefined;
});
});
if (!!window.SpeechSDK) {
SpeechSDK = window.SpeechSDK;
startSpeakTextAsyncButton.disabled = false;
if (typeof RequestAuthorizationToken === "function") {RequestAuthorizationToken();}
}
});
</script>
</body>
</html>
Microsoft认知服务语音SDK JavaScript快速启动
说话
var authorizationEndpoint=“token.php”;
函数RequestAuthorizationToken(){
if(授权端点){
var a=新的XMLHttpRequest();
a、 打开(“获取”,授权端点);
a、 setRequestHeader(“内容类型”、“应用程序/x-www-form-urlencoded”);
a、 发送(“”);
a、 onload=函数(){
var token=JSON.parse(atob(this.responseText.split(“.”[1]);
serviceRegion.value=token.region;
authorizationToken=this.responseText;
subscriptionKey.disabled=true;
}
}
}
var StartPeakTextAsyncButton;
var serviceRegion=“西欧”;
//对于测试:
//var voiceName=“HeddaRUS”;
//var voiceLanguage=“de de”;
var下标键;
var授权令牌;
var SpeechSDK;
无功功率合成器;
document.addEventListener(“DOMContentLoaded”,函数(){
StartPeakTextAsyncButton=document.getElementById(“StartPeakTextAsyncButton”);
subscriptionKey=document.getElementById(“subscriptionKey”);
StartPeakTextAsyncButton.addEventListener(“单击”),函数(){
StartPeakTextAsyncButton.disabled=true;
speechConfig=SpeechSDK.speechConfig.fromAuthorizationToken(authorizationToken,serviceRegion);
//我不知道代码应该是什么样子:
//speechConfig=SpeechSDK.speechConfig.setSpeechSynthesisLanguage(voiceLanguage);
//speechConfig=SpeechSDK.speechConfig.setSpeechSynthesisVoiceName(voiceName);
合成器=新SpeechSDK.SpeechSynthesizer(speechConfig);
//输出应为德语:
让我们输入text=“我是德国斯普拉奇大学的学生,我不是学生!”;
synthesizer.speakTextAsync(
输入文本,
功能(结果){
StartPeakTextAsyncButton.disabled=false;
window.console.log(结果);
合成器关闭();
合成器=未定义;
});
});
如果(!!window.SpeechSDK){
SpeechSDK=window.SpeechSDK;
StartPeakTextAsyncButton.disabled=false;
if(typeof RequestAuthorizationToken==“函数”){RequestAuthorizationToken();}
}
});
要进行快速测试,您可以在speechConfig
中指定您的语言和语音,如下所示:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Microsoft Cognitive Services Speech SDK JavaScript Quickstart</title>
<meta charset="utf-8" />
</head>
<body>
<button id="startSpeakTextAsyncButton" onclick="synthesizeSpeech()">speak</button>
<!-- Speech SDK reference sdk. -->
<script src="microsoft.cognitiveservices.speech.sdk.bundle.js"></script>
<script>
function synthesizeSpeech() {
var speechConfig = SpeechSDK.SpeechConfig.fromSubscription("<your subscription key,you can find it on azure portal=> Kesy and Endpoints blade>", "<your region>");
speechConfig.speechSynthesisVoiceName = "Microsoft Server Speech Text to Speech Voice (de-DE, Hedda)";
speechConfig.SpeechSynthesisLanguage = "de-DE";
var synthesizer = new SpeechSDK.SpeechSynthesizer(speechConfig);
let inputText = "Ich möchte es auf deutsche Sprache setzen, weiß aber nicht wie!";
synthesizer.speakTextAsync(
inputText,
function (result) {
startSpeakTextAsyncButton.disabled = false;
window.console.log(result);
synthesizer.close();
synthesizer = undefined;
});
}
</script>
</body>
</html>
Microsoft认知服务语音SDK JavaScript快速启动
说话
函数综合语音(){
var speechConfig=SpeechSDK.speechConfig.fromSubscription(“Kesy和端点刀片>”,“”);
speechConfig.speechSynthesisVoiceName=“Microsoft服务器语音文本到语音语音(de de,Hedda)”;
speechConfig.SpeechSynthesisLanguage=“de de”;
var synthesizer=new SpeechSDK.SpeechSynthesizer(speechConfig);
让我们输入text=“我是德国斯普拉奇大学的学生,我不是学生!”;
synthesizer.speakTextAsync(
输入文本,
功能(结果){
StartPeakTextAsyncButton.disabled=false;
window.console.log(结果);
合成器关闭();
合成器=未定义;
});
}
您可以在第130行找到所有语音名称。这不是你的错,似乎没有正式的js示例:(为了快速测试,你可以在
speechConfig
中指定你的语言和语音,如下所示:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Microsoft Cognitive Services Speech SDK JavaScript Quickstart</title>
<meta charset="utf-8" />
</head>
<body>
<button id="startSpeakTextAsyncButton" onclick="synthesizeSpeech()">speak</button>
<!-- Speech SDK reference sdk. -->
<script src="microsoft.cognitiveservices.speech.sdk.bundle.js"></script>
<script>
function synthesizeSpeech() {
var speechConfig = SpeechSDK.SpeechConfig.fromSubscription("<your subscription key,you can find it on azure portal=> Kesy and Endpoints blade>", "<your region>");
speechConfig.speechSynthesisVoiceName = "Microsoft Server Speech Text to Speech Voice (de-DE, Hedda)";
speechConfig.SpeechSynthesisLanguage = "de-DE";
var synthesizer = new SpeechSDK.SpeechSynthesizer(speechConfig);
let inputText = "Ich möchte es auf deutsche Sprache setzen, weiß aber nicht wie!";
synthesizer.speakTextAsync(
inputText,
function (result) {
startSpeakTextAsyncButton.disabled = false;
window.console.log(result);
synthesizer.close();
synthesizer = undefined;
});
}
</script>
</body>
</html>
Microsoft认知服务语音SDK JavaScript快速启动
说话
函数综合语音(){
var speechConfig=SpeechSDK.speechConfig.fromSubscription(“Kesy和端点刀片>”,“”);
speechConfig.speechSynthesisVoiceName=“Microsoft服务器语音文本到语音语音(de de,Hedda)”;
speechConfig.SpeechSynthesisLanguage=“de de”;
var synthesizer=new SpeechSDK.SpeechSynthesizer(speechConfig);
让我们输入text=“我是德国斯普拉奇大学的学生,我不是学生!”;
synthesizer.speakTextAsync(
输入文本,
功能(结果){
StartPeakTextAsyncButton.disabled=false;
window.console.log(结果);
合成器关闭();
合成器=未定义;
});
}
您可以在第130行找到所有语音名称。这不是您的错,似乎没有正式的js示例:(非常感谢。您是对的,网络中既没有正式的示例,也没有非正式的示例。昨天我通过尝试短版本找到了:speechConfig.speechSynthesisVoiceName=“de KatjaNeural”;效果很好。不幸的是,似乎不可能在文本中直接添加这样的标记来说话。@kairo,欢迎!如果对您有帮助,请单击答案旁边的复选标记,将其从灰色切换到填充,将其标记为答案,以便帮助他人。非常感谢。您是对的,没有她无论是官方还是非官方的样本都可以在网上找到。昨天我通过尝试简短的版本发现:speechConfig.speechSynthesisVoiceName=“de de KatjaNeural”;它工作得很好。不幸的是,似乎不可能在文本中直接添加标记来说话。@kairo