前提・実現したいこと
gTTSで日本語を読み上げさせた音声を保存したいのですがエラーが起きます。
発生している問題・エラーメッセージ
-------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-24-daa5fb84901f> in <module> 6 filename = r'C:\Users\sern3\Desktop\petgazou\voice\mugi.mp3' #mp3ファイル 7 ----> 8 tts.save(filename) c:\users\sern3\appdata\local\programs\python\python36\lib\site-packages\gtts\tts.py in save(self, savefile) 293 # no audio stream in response 294 raise gTTSError(tts=self, response=r) --> 295 log.debug("part-%i written to %s", idx, fp) 296 except (AttributeError, TypeError) as e: 297 raise TypeError( c:\users\sern3\appdata\local\programs\python\python36\lib\site-packages\gtts\tts.py in write_to_fp(self, fp) 249 Raises: 250 :class:`gTTSError`: When there's an error with the API request. --> 251 TypeError: When ``fp`` is not a file-like object that takes bytes. 252 253 """ c:\users\sern3\appdata\local\programs\python\python36\lib\site-packages\gtts\tts.py in _prepare_requests(self) 192 193 text_parts = self._tokenize(self.text) --> 194 log.debug("text_parts: %s", str(text_parts)) 195 log.debug("text_parts: %i", len(text_parts)) 196 assert text_parts, 'No text to send to TTS API' c:\users\sern3\appdata\local\programs\python\python36\lib\site-packages\gtts_token\gtts_token.py in calculate_token(self, text, seed) 26 27 ---> 28 def calculate_token(self, text, seed=None): 29 """ Calculate the request token (`tk`) of a string 30 :param text: str The text to calculate a token for c:\users\sern3\appdata\local\programs\python\python36\lib\site-packages\gtts_token\gtts_token.py in _get_token_key(self) 57 a %= 1E6 58 a = int(a) ---> 59 return str(a) + "." + str(a ^ int(first_seed)) 60 61 def _get_token_key(self, retry=0): ValueError: Unable to find token seed! Did https://translate.google.com change?
該当のソースコード
Python
1from gtts import gTTS 2 3mytext = "これは麦茶です" 4tts = gTTS(text=mytext, lang='ja') 5 6filename = r'C:\Users\sern3\Desktop\petgazou\voice\mugi.mp3' #mp3ファイル 7 8tts.save(filename)
あなたの回答
tips
プレビュー