google cloud text to speechでテキストを音声に変換する作業をしています。
動作確認済みですので他コード部分は省略しますが、最後の行、(text="Hello, World!")の部分を、べた打ちではなく、txtファイルを指定し読み込ませたいのですがうまくいきません。
次のようにやってみたのですが、
text_path = r"C:\Users\Eizo\Desktop\awesome\texttest.text"
synthesis_input = texttospeech.types.SynthesisInput(text = text_path)
TypeError: No positional arguments allowedとエラーになります。
定義の仕方がまずいのだとは思うのですが、おわかりになる方がいらっしゃれば対処法ご教示いただければ幸いです。
なお、以下 python3環境 で記述しています。
def run_quickstart(): # [START tts_quickstart] """Synthesizes speech from the input string of text or ssml. Note: ssml must be well-formed according to: https://www.w3.org/TR/speech-synthesis/ """ from google.cloud import texttospeech # Instantiates a client client = texttospeech.TextToSpeechClient() # Set the text input to be synthesized synthesis_input = texttospeech.types.SynthesisInput**(text="Hello, World!")**
ちなみに自分ではこんな感じで読み取りコードを考えてみたのですが、だめでした。
text_path = r"C:\Users\Eizo\Desktop\awesome\texttest.text"
f = open(text_path)
data1 = f.read()
f.close()
print type(data1)
lines1 = data1.split('\n')
print type(lines1)
for line in lines1:
print line
synthesis_input = texttospeech.types.SynthesisInput(text = data1)
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/06/09 06:12