Google Cloud Text-To-Speech で動的にパラメーターを指定したい。
紹介
Python初心者です。どうぞよろしくお願い致します。
初めて投稿致します、投稿の仕方などまだよくわかっておりません。
不足/不明な点などなんでも追加でご報告しますのでご指導くださいませ。
現在、上記サービスを利用してテキストを音声ファイルに変換する機能を実装しています。
下記のコードで、幾つかのパラメータを settings.py で設定し動的に変更できればと考えています。
音声変換コード
# encoding:utf-8 from google.cloud import texttospeech from django.conf import settings # Instantiates a client client = texttospeech.TextToSpeechClient() # Set the text input to be synthesized synthesis_input = texttospeech.types.SynthesisInput(text="Hello, World!") # Build the voice request, select the language code ("en-US") and the ssml # voice gender ("neutral") voice = texttospeech.types.VoiceSelectionParams( language_code='en-US', ssml_gender=texttospeech.enums.SsmlVoiceGender.NEUTRAL) # ↑ MALE, FEMALE, NEUTRAL # Select the type of audio file you want returned audio_config = texttospeech.types.AudioConfig( audio_encoding=texttospeech.enums.AudioEncoding.MP3) # ↑ MP3, OGG_OPUS, OGG_OPUS # Perform the text-to-speech request on the text input with the selected # voice parameters and audio file type response = client.synthesize_speech(synthesis_input, voice, audio_config) # The response's audio_content is binary. with open('output.mp3', 'wb') as out: # Write the response to the output file. out.write(response.audio_content) print('Audio content written to file "output.mp3"')
settings.py
GENDER = NEUTRAL ENCODEING = MP3
##質問
いろいろ調べてみたのですが、文字列を変数に変換するのに
exec() とか locals()/globals() を使うなどの方法が紹介されていましたが、
この場合の実装方法を見つけることができませんでした。
具体的な方法、また代替案などありましたらご教示頂ければ幸甚です。
どうぞよろしくお願い致します。
#####開発環境
Python 2.7.4
Django 1.5
使用ライブラリ google-cloud-texttospeech
######Google Cloud 音声合成API
Google Cloud Text-To-Speech
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/11/07 07:58
2018/11/07 08:52
2018/11/07 09:18
2018/11/07 09:22 編集
2018/11/11 07:02
2018/11/12 05:52
2018/11/12 13:32