我使用 Azure 的语音工作室训练、创建和部署了自定义语音模型。
在部署模型页面上,我获得了资源密钥、服务区域和端点 ID。我在下面的代码中使用了端点 ID(我确信它是正确的)。
但是,我收到此错误: 错误代码:1007。错误详细信息:部署 ID XXXXX 无效 USP 状态:TurnStarted。接收到的音频大小:0 字节。] 已取消:您是否设置了语音资源键和区域值?
任何人都可以提示为什么它不起作用吗?
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.CognitiveServices.Speech;
using Microsoft.CognitiveServices.Speech.Audio;
class Program
{
// This example requires environment variables named "SPEECH_KEY" and "SPEECH_REGION"
static string speechKey = "my-resource-key";
static string speechRegion = "my-region";
static void OutputSpeechSynthesisResult(SpeechSynthesisResult speechSynthesisResult, string text)
{
switch (speechSynthesisResult.Reason)
{
case ResultReason.SynthesizingAudioCompleted:
Console.WriteLine($"Speech synthesized for text");
break;
case ResultReason.Canceled:
var cancellation = SpeechSynthesisCancellationDetails.FromResult(speechSynthesisResult);
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 set the speech resource key and region values?");
}
break;
default:
break;
}
}
async static Task Main(string[] args)
{
var speechConfig = SpeechConfig.FromSubscription(speechKey, speechRegion);
// The language of the voice that speaks.
speechConfig.SpeechSynthesisVoiceName = "MyNeuralVoice";
speechConfig.EndpointId = "my-endpoint-id";
using (var speechSynthesizer = new SpeechSynthesizer(speechConfig))
{
// Get text from the console and synthesize to the default speaker.
Console.WriteLine("Enter some text that you want to speak >");
string text = Console.ReadLine();
var speechSynthesisResult = await speechSynthesizer.SpeakTextAsync(text);
OutputSpeechSynthesisResult(speechSynthesisResult, text);
}
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
}
我从我这边尝试了你的代码并成功将文本转换为语音。
注:
按照以下步骤创建文本到语音自定义神经语音:
在下面的代码中使用上面的 Endpoint key、region 和 deploymentId。
代码:
using Microsoft.CognitiveServices.Speech;
class Program
{
static string speechKey = "<speech_key>";
static string speechRegion = "<speech_region>";
static void OutputSpeechSynthesisResult(SpeechSynthesisResult speechSynthesisResult, string text)
{
switch (speechSynthesisResult.Reason)
{
case ResultReason.SynthesizingAudioCompleted:
Console.WriteLine($"Speech synthesized for text");
break;
case ResultReason.Canceled:
var cancellation = SpeechSynthesisCancellationDetails.FromResult(speechSynthesisResult);
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 set the speech resource key and region values?");
}
break;
default:
break;
}
}
async static Task Main(string[] args)
{
var speechConfig = SpeechConfig.FromSubscription(speechKey, speechRegion);
speechConfig.SpeechSynthesisVoiceName = "en-US"; //Replace your voice name here, I used en-US
speechConfig.EndpointId = "<deploymentID>";
using (var speechSynthesizer = new SpeechSynthesizer(speechConfig))
{
Console.WriteLine("Enter some text that you want to speak >");
string text = Console.ReadLine();
var speechSynthesisResult = await speechSynthesizer.SpeakTextAsync(text);
OutputSpeechSynthesisResult(speechSynthesisResult, text);
}
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
}
输出:
代码运行成功,我收到以下提示,需要输入一些文本输入以获得语音输出:
我输入了文字嗨卡玛利。你好吗? 并听到了所提供的输入文本的语音输出,从而产生了以下消息:
Enter some text that you want to speak >
Hi Kamali. How are you?
Speech synthesized for text
Press any key to exit...
参考:
检查此MSDOC以将文本转换为语音。