调用SpeakSsmlAsync
(Microsoft Speech SDK)时,返回以下错误消息:
> CANCELED: Reason=Error
> CANCELED: ErrorCode=BadRequest
> CANCELED: ErrorDetails=[HTTPAPI result code = HTTPAPI_OK. HTTP status code=400.]
> CANCELED: Did you update the subscription info?
复制步骤:
从以下位置下载快速入门示例 https://github.com/Azure-Samples/cognitive-services-speech-sdk/tree/master/quickstart/text-to-speech/csharp-dotnet-windows
用自己的值替换订阅ID和区域,设置为活动 如文档中所述配置,清理并重建项目
启动程序并输入诸如“ abracadabra”之类的文本
->工作正常(使用SpeakTextAsync
)
将SpeakTextAsync
替换为SpeakSsmlAsync
启动程序并输入一些文字
-> ErrorCode = BadRequest
使用正确的SSML代码重试,例如<speak version="1.0" xmlns="https://www.w3.org/2001/10/synthesis" xml:lang="en-US">abracadabra</speak>
“
-> ErrorCode = BadRequest
系统
代码
using System;
using System.Threading.Tasks;
using Microsoft.CognitiveServices.Speech;
namespace helloworld
{
class Program
{
private static string endpointSpeechKey = "<MyOwnServiceKey>";
private static string region = "westeurope";
public static async Task SynthesisToSpeakerAsync()
{
var config = SpeechConfig.FromSubscription(endpointSpeechKey, region);
using (var synthesizer = new SpeechSynthesizer(config))
{
Console.WriteLine("Type some text that you want to speak...");
Console.Write("> ");
string text = Console.ReadLine();
using (var result = await synthesizer.SpeakSsmlAsync(text))
{
if (result.Reason == ResultReason.SynthesizingAudioCompleted)
{
Console.WriteLine($"Speech synthesized to speaker for text [{text}]");
}
else if (result.Reason == ResultReason.Canceled)
{
var cancellation = SpeechSynthesisCancellationDetails.FromResult(result);
Console.WriteLine($"CANCELED: Reason={cancellation.Reason}");
if (cancellation.Reason == CancellationReason.Error)
{
Console.WriteLine($"CANCELED: ErrorCode={cancellation.ErrorCode}");
Console.WriteLine($"CANCELED: ErrorDetails=[{cancellation.ErrorDetails}]");
Console.WriteLine($"CANCELED: Did you update the subscription info?");
}
}
}
// This is to give some time for the speaker to finish playing back the audio
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
}
static void Main()
{
SynthesisToSpeakerAsync().Wait();
}
}
}
调试屏幕截图
答案 0 :(得分:0)
Azure仅在包含语音标签时才接受SSML。否则,您会收到http-400错误。
使用下面的代码可以成功调用SpeakSsmlAsync:
gsl_rng* Initialize() { //INITIALIZE
int rand_seed = 77711; //any integer
srand(time(NULL));
const gsl_rng_type* gsl_rng_T;
gsl_rng* r; //The random variable
gsl_rng_env_setup();
gsl_rng_default_seed = rand_seed;
gsl_rng_T = gsl_rng_default;
r = gsl_rng_alloc(gsl_rng_T);
return r;
}
int random_int(int n) { //Generate integer random variable in [0,n[
static gsl_rng* r2 = Initialize(); //Initialize as static
return gsl_rng_uniform_int(r2, n);
}
void Calculations(/*Variables that have nothing to do with the random numbers*/) {
//Stuff
int position = random_int(Info.I);
//Info.I is an integer member of the class "Info", its value changes //with each call of the function "Calculations".
//.
//.
//.
return;
}
在搜索Microsoft SSML时要当心。两者之间有区别
https://docs.microsoft.com/en-us/azure/cognitive-services/speech-service/speech-synthesis-markup
(这是针对Azure Speech服务进行编程时想要的)和
https://docs.microsoft.com/en-us/cortana/skills/speech-synthesis-markup-language
答案 1 :(得分:0)
是的,Azure TTS服务仅接受带有语音标签的SSML。
原因是语音太多,因此最好明确指定要使用的语音。