【问题标题】:How do I input SSML in Google TTS? (C#)如何在 Google TTS 中输入 SSML? (C#)
【发布时间】:2023-03-17 00:33:01
【问题描述】:

我一直在使用 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\"");
    }
}

}

【问题讨论】:

    标签: c# google-cloud-platform text-to-speech google-text-to-speech


    【解决方案1】:

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

    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>"
    };
    

    Speech Synthesis Markup Language (SSML)

    【讨论】:

    • 嗨,非常感谢您为 John 提供答案,我可以确认它有效。
    猜你喜欢
    • 2020-10-07
    • 2013-05-14
    • 2021-05-13
    • 2021-04-28
    • 2020-03-16
    • 1970-01-01
    • 1970-01-01
    • 2020-08-17
    • 2018-08-02
    相关资源
    最近更新 更多