Настройка параметров клиентской библиотеки Google TTS для китайского языка

Я пробую texttospeech с Google Cloud API. Вот пример кода, и он хорошо работает для английского языка; но когда я меняю language_code = 'en-US' на 'zh-CN' и устанавливаю входной текст на китайское слово, показываю ошибку: 400 Нет голоса TTS, соответствующего запросу TTS. Исправьте параметры выбора голоса и повторите попытку.

import argparse
# [START tts_synthesize_text]
def synthesize_text(text):
    """Synthesizes speech from the input string of text."""
    from google.cloud import texttospeech
    client = texttospeech.TextToSpeechClient()

    input_text = texttospeech.types.SynthesisInput(text=text)

# Note: the voice can also be specified by name.
# Names of voices can be retrieved with client.list_voices().
    voice = texttospeech.types.VoiceSelectionParams(
        language_code='en-US',
        ssml_gender=texttospeech.enums.SsmlVoiceGender.FEMALE)

    audio_config = texttospeech.types.AudioConfig(
        audio_encoding=texttospeech.enums.AudioEncoding.MP3)

    response = client.synthesize_speech(input_text, voice, audio_config)

    # The response's audio_content is binary.
    with open('output.mp3', 'wb') as out:
        out.write(response.audio_content)
        print('Audio content written to file "output.mp3"')
# [END tts_synthesize_text]

Пожалуйста, помогите, как установить параметр, когда я использую китайский язык?


person PHE    schedule 10.04.2018    source источник
comment
На веб-сайте Google Cloud кажется, что он еще не поддерживает китайский голосовой API.   -  person PHE    schedule 23.04.2018
comment
ты решил проблему? Я пытаюсь использовать tts Google с китайским языком и столкнулся с той же проблемой. Я не очень разбираюсь в javascript.   -  person Derekyy    schedule 28.05.2018


Ответы (1)


Я использую пакет gTTS для решения этой проблемы, и он мне подходит, вот код:

def text_to_speech_gtts(res_ans):
    from gtts import gTTS
    volume=1.0
    music_file="ans01.mp3"
    tts = gTTS(text=res_ans, lang='zh-tw')
    tts.save(music_file)
    freq = 25000    # audio CD quality
    bitsize = -16    # unsigned 16 bit
    channels = 2     # 1 is mono, 2 is stereo
    buffer = 2048    # number of samples (experiment to get best sound)
    pg.mixer.init(freq, bitsize, channels, buffer)
    # volume value 0.0 to 1.0
    pg.mixer.music.set_volume(volume)
    clock = pg.time.Clock()
    try:
        pg.mixer.music.load(music_file)
    except pg.error:
        print("File {} not found! ({})".format(music_file, pg.get_error()))

    pg.mixer.music.play()
    while pg.mixer.music.get_busy():
        # check if playback has finished
        clock.tick(30) #
    pg.mixer.music.stop()
    pg.mixer.quit()  
person PHE    schedule 29.05.2018