1. 程式人生 > >通過google cloud API 使用 WaveNet

通過google cloud API 使用 WaveNet

targe size input ssm ioc LV tex ica amp

Cloud Text-to-Speech 中使用了WaveNet,用於TTS,頁面上有Demo。目前是BETA版

使用方法

  • 註冊及認證參考:Quickstart: Text-to-Speech
  • 安裝google clould 的python庫
  • 安裝 Google Cloud Text-to-Speech API Python 依賴(Dependencies),參見github說明
  • ----其中包括了,安裝pip install google-cloud-texttospeech==0.1.0

為了implicit調用,設置環境變量GOOGLE_APPLICATION_CREDENTIALS到你的API Key(json文件),完成後重啟

技術分享圖片

python腳本:text到mp3

# [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]

  

WaveNet特性

目前支持的6種voice type

技術分享圖片

技術分享圖片

參數說明

https://cloud.google.com/text-to-speech/docs/reference/rest/v1beta1/text/synthesize#audioconfig

  • input_text

技術分享圖片

  • voice

技術分享圖片

  • audio_config

技術分享圖片

技術分享圖片

通過google cloud API 使用 WaveNet