通過google cloud API 使用 WaveNet


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

  

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM