如何在Google TTS中输入SSML?(C#)
我一直在使用谷歌提供的示例C#代码来熟悉谷歌TTS。我想输入ssml,但我不知道怎么做。如果有人能告诉我需要更改哪行代码,我将非常感激 我尝试将下面的“文本”更改为“SSML”,但没有成功。我还尝试在输入的文本中使用SSML标记,但这也不起作用 我已经浏览了相关的GoogleSSML文档,但我不知道我做错了什么如何在Google TTS中输入SSML?(C#),c#,google-cloud-platform,text-to-speech,google-text-to-speech,C#,Google Cloud Platform,Text To Speech,Google Text To Speech,我一直在使用谷歌提供的示例C#代码来熟悉谷歌TTS。我想输入ssml,但我不知道怎么做。如果有人能告诉我需要更改哪行代码,我将非常感激 我尝试将下面的“文本”更改为“SSML”,但没有成功。我还尝试在输入的文本中使用SSML标记,但这也不起作用 我已经浏览了相关的GoogleSSML文档,但我不知道我做错了什么 using Google.Cloud.TextToSpeech.V1; using System; using System.IO; namespace TextToSpeechApi
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>"
};
var输入=新的综合输入
{
Ssml=“这是谷歌云文本语音API的演示。该API非常易于使用。SSMLis也易于使用。”
};
您好,非常感谢您提供此问题的答案,John,我可以确认它是有效的。