如何在谷歌TTS中输入SSML?(C#)



我一直在使用Google提供的示例C#代码来熟悉Google TTS。我想输入 ssml,但我无法弄清楚如何做到这一点。如果有人能告诉我需要更改哪行代码,我将不胜感激。

我尝试将下面的"文本"更改为"SSML",但这不起作用。我还尝试在输入的文本中使用 SSML 标签,但这也没有用。

我已经浏览了相关的Google SSML文档,但我无法弄清楚我做错了什么。

using Google.Cloud.TextToSpeech.V1;
using System;
using System.IO;
namespace TextToSpeechApiDemo
{
class Program
{
    static void Main(string[] args)
    {
        var client = TextToSpeechClient.Create();
        // The input to be synthesized, can be provided as text or SSML.
        var input = new SynthesisInput
        {
            Text = "This is a demonstration of the Google Cloud Text-to-Speech API"
        };
        // Build the voice request.
        var voiceSelection = new VoiceSelectionParams
        {
            LanguageCode = "en-US",
            SsmlGender = SsmlVoiceGender.Female
        };
        // Specify the type of audio file.
        var audioConfig = new AudioConfig
        {
            AudioEncoding = AudioEncoding.Mp3
        };
        // Perform the text-to-speech request.
        var response = client.SynthesizeSpeech(input, voiceSelection, audioConfig);
        // Write the response to the output file.
        using (var output = File.Create("output.mp3"))
        {
            response.AudioContent.WriteTo(output);
        }
        Console.WriteLine("Audio content written to file "output.mp3"");
    }
}

}

解决方案非常简单。更改代码部分:

var input = new SynthesisInput
{
    Text = "This is a demonstration of the Google Cloud Text-to-Speech API"
};

对此:

var input = new SynthesisInput
{
    Ssml = "<speak>This is a demonstration of the Google Cloud Text-to-Speech API.<break time="1s"/>This API is very easy to use.<break time="1s"/><say-as interpret-as="characters">SSML</say-as>is also easy to use.</speak>"
};

语音合成标记语言 (SSML)

最新更新