【发布时间】: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