如何在 Google TTS 中输入 SSML? (C#)
How do I input SSML in Google TTS? (C#)
我一直在使用 Google 提供的示例 C# 代码来熟悉 Google TTS。我想输入 ssml,但不知道该怎么做。如果有人能告诉我需要更改哪一行代码,那么我将不胜感激。
我尝试将下面的 'Text' 更改为 '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>"
};
我一直在使用 Google 提供的示例 C# 代码来熟悉 Google TTS。我想输入 ssml,但不知道该怎么做。如果有人能告诉我需要更改哪一行代码,那么我将不胜感激。
我尝试将下面的 'Text' 更改为 '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>"
};