ffmpegについてのエラーが発生しました。
Pythonを用いてDiscordでテキストを音声で読んでくれるbotを作成中にエラーが発生しました。mp3ファイル自体は作成ができていて再生できるため、
voiceChannel.play(discord.FFmpegPCMAudio(file))でエラーが発生しているようです。
インストールしたffmpegへのpathは通しており、コマンドプロンプトで「ffmpeg」と打ち込んで正常にpathが通っていることは確認済みです。pip install ffmpegもやっています。初心者ですのでご教授願いたいです。
実現したいこと
Discordでテキストチャンネルに送られたテキストを呼んでくれるbotを作成したい。
発生している問題・エラーメッセージ
Ignoring exception in on_message Traceback (most recent call last): File "C:\Users\spla0\Anaconda3\lib\site-packages\discord\client.py", line 343, in _run_event await coro(*args, **kwargs) File "<ipython-input-1-c197e1d9f3e3>", line 75, in on_message play_voice(message.content) File "<ipython-input-1-c197e1d9f3e3>", line 40, in play_voice voiceChannel.play(discord.FFmpegPCMAudio(file)) File "C:\Users\spla0\Anaconda3\lib\site-packages\discord\player.py", line 225, in __init__ super().__init__(source, executable=executable, args=args, **subprocess_kwargs) File "C:\Users\spla0\Anaconda3\lib\site-packages\discord\player.py", line 138, in __init__ self._process = self._spawn_process(args, **kwargs) File "C:\Users\spla0\Anaconda3\lib\site-packages\discord\player.py", line 147, in _spawn_process raise ClientException(executable + ' was not found.') from None discord.errors.ClientException: ffmpeg was not found.
該当のソースコード
Python
1import discord 2import html 3import ffmpeg 4from discord.channel import VoiceChannel 5from google.cloud import texttospeech 6import os 7 8os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = "C:\\Users\\spla0\\PassCordFolder\\key.json" 9TOKEN = "自分のトークンです。" 10client = discord.Client() 11 12voiceChannel: VoiceChannel 13#textをssmlに変換 14def text_to_ssml(text): 15 escaped_lines = html.escape(text) 16 ssml = "{}".format(escaped_lines.replace("\n",'\n<break time="1s"/>')) 17 return ssml 18 19def ssml_to_speech(ssml, file, language_code, gender): 20 ttsClient = texttospeech.TextToSpeechClient() 21 synthesis_input = texttospeech.SynthesisInput(text=ssml) 22 voice = texttospeech.VoiceSelectionParams( 23 language_code=language_code, ssml_gender=gender 24 ) 25 audio_config = texttospeech.AudioConfig( 26 audio_encoding=texttospeech.AudioEncoding.MP3 27 ) 28 response = ttsClient.synthesize_speech( 29 input=synthesis_input, voice=voice, audio_config=audio_config 30 ) 31 with open(file, "wb") as out: 32 out.write(response.audio_content) 33 print("Audio content written to file " + file) 34 return file 35 36def play_voice(text): 37 global voiceChannel 38 ssml = text_to_ssml(text) 39 file = ssml_to_speech(ssml, "voice.mp3", "ja-JP", texttospeech.SsmlVoiceGender.MALE) 40 voiceChannel.play(discord.FFmpegPCMAudio(file)) 41 42@client.event 43async def on_ready(): 44 print('Login!!!') 45 print(discord.__version__) 46 47@client.event 48async def on_message(message: discord.Message): 49 global voiceChannel 50 if message.author.bot: 51 return 52 53 if message.content == "c.com": 54 if message.author.voice is None: 55 await message.channel.send("あなたはボイスチャンネルに接続していません。") 56 return 57 voiceChannel = await VoiceChannel.connect(message.author.voice.channel) 58 await message.channel.send("接続しました。") 59 60 elif message.content == "c.del": 61 if message.guild.voice_client is None: 62 await message.channel.send("接続していません。") 63 return 64 voiceChannel.stop() 65 await voiceChannel.disconnect() 66 await message.channel.send("切断しました。") 67 68 play_voice(message.content) 69 70client.run(TOKEN)
試したこと
ffmpegの再インストールなどやってみましたが上手くいきませんでした。
補足情報(FW/ツールのバージョンなど)
Python3.8.3
Google cloud関連の設定も全て完了させているはずです。
あなたの回答
tips
プレビュー