Azure 神经语音:部署 ID 无效

问题描述 投票:0回答:1

我使用 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();
    }
}


c# azure azure-cognitive-services azure-speech
1个回答
0
投票

我从我这边尝试了你的代码并成功将文本转换为语音。

注:

  1. 每当提出请求时,请确保状态为成功。如果是正在处理已暂停,您将收到错误。

enter image description here

  1. 如果我提供了不正确的deploymentID,我也会收到如下所示的相同错误:

enter image description here

按照以下步骤创建文本到语音自定义神经语音

  1. 转到Speech Studio (microsoft.com)并单击创建自定义语音,如下所示:

enter image description here

  1. 单击创建项目。我已经有一个名为 kamtts 的项目,如下所示:

enter image description here

  1. 转到记录并构建。记录一些样本(我记录了32个样本),然后点击训练模型,如下:

enter image description here

  1. 转到查看模型并检查模型中的详细信息,如下所示:

enter image description here

  1. 转到 部署模型 > 单击 部署模型 部署模型,如下所示:

enter image description here

  1. 转到您的部署模型 > 复制 Endpoint keyregiondeploymentId,如下所示:

enter image description here enter image description here

在下面的代码中使用上面的 Endpoint keyregiondeploymentId

代码:

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 image description here

我输入了文字嗨卡玛利。你好吗? 并听到了所提供的输入文本的语音输出,从而产生了以下消息:

enter image description here

Enter some text that you want to speak >
Hi Kamali. How are you?
Speech synthesized for text
Press any key to exit...

参考:

检查此MSDOC以将文本转换为语音

© www.soinside.com 2019 - 2024. All rights reserved.