【问题标题】:Google Cloud TTS Voice selection谷歌云 TTS 语音选择
【发布时间】:2018-12-07 05:23:05
【问题描述】:

我刚开始使用谷歌的 TTS api,当我列出可用的语音 api 时,将语音的名称列为

  • tr-TR-标准-A
  • tr-TR-标准-B
  • ...

我应该在下面的代码中写什么来选择例如 Standart-B 语音?

texttospeech.types.VoiceSelectionParams(language_code='tr-TR')

【问题讨论】:

  • 欢迎来到 Stack Overflow。您能否告诉我们更多关于您使用的平台的信息,最好是您目前如何调用 API 的示例代码?这样更容易举一个具体的例子。
  • 话虽如此,我可以写一个 C# 示例,然后希望你能接受...
  • 抱歉,我用的是python。
  • 正确 - 我在答案末尾添加了一个 sn-p。

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


【解决方案1】:

这是一个 C# 示例 - 您需要在 VoiceSelectionParams 中指定语言代码和名称:

using Google.Cloud.TextToSpeech.V1;
using System;
using System.IO;

class Program
{
    static void Main(string[] args)
    {
        var client = TextToSpeechClient.Create();

        // List the voices, just for reference
        foreach (var voice in client.ListVoices("tr-TR").Voices)
        {
            Console.WriteLine(voice.Name);
        }

        // Synthesize some speech
        var input = new SynthesisInput { Text = "This is a demo of Google Cloud text to speech" };
        // The language code is always required, even when it's sort of part of the name
        var voiceSelection = new VoiceSelectionParams
        {
            LanguageCode = "tr-TR",
            Name = "tr-TR-Standard-B"
        };
        var audioConfig = new AudioConfig { AudioEncoding = AudioEncoding.Mp3 };
        var response = client.SynthesizeSpeech(input, voiceSelection, audioConfig);
        File.WriteAllBytes("test.mp3", response.AudioContent.ToByteArray());
    }
}

从文档来看,我认为在 Python 中你会想要:

voice = texttospeech.types.VoiceSelectionParams(
    language_code='tr-TR',
    name='tr-TR-Standard-B')

【讨论】:

  • @TugrulAgrikliStudent:你能提供更多细节吗?我假设您遇到了一些描述错误 - 那是什么错误?如果没有更多信息,我无法帮助您。 (C# 代码肯定确实工作。)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-07-11
  • 1970-01-01
  • 2023-04-09
  • 1970-01-01
  • 2017-03-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多