From 41bb8756fd73b648f1106135b4a21d6f5adf6335 Mon Sep 17 00:00:00 2001 From: majmongoose Date: Mon, 12 Feb 2024 13:57:42 -0500 Subject: [PATCH] Multiple Update gitignore Update to have some more logic --- .gitignore | 5 ++++- pagebot.py | 35 +++++++++++++++++++++++------------ 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index 7ea4e73..5536098 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,9 @@ +# Ignore pycache +__pycache__/ # Ignore ffmpeg executable ffmpeg -ffprobe +ffmpeg.exe +output_audio.wav # Ignore secrets file secrets_file.py \ No newline at end of file diff --git a/pagebot.py b/pagebot.py index d9fff1b..a3e170e 100644 --- a/pagebot.py +++ b/pagebot.py @@ -24,17 +24,22 @@ class MyHandler(FileSystemEventHandler): print("New MP3!") text = "" if secrets_file.speech_to_text: + print("Converting To Text") text = convert_to_text(filepath) + print("Converting to MP4") mp4_file = convert_to_mp4(filepath) + print("Sending to Discord") client.loop.create_task(upload_to_discord(mp4_file,text)) - os.remove(filepath) + #time.sleep(10) + print("Removing original file.") + #os.remove(filepath) ##convert mp3 to mp4 def convert_to_mp4(mp3_file): try: time.sleep(10) mp4_file = os.path.splitext(mp3_file)[0] + '.mp4' - command = f'./ffmpeg -loop 1 -i img/blacksmall.jpg -i "{mp3_file}" -c:a aac -b:a 192k -c:v libx264 -pix_fmt yuv420p -shortest "{mp4_file}"' + command = f'ffmpeg -loop 1 -i img/blacksmall.jpg -i "{mp3_file}" -c:a aac -b:a 192k -c:v libx264 -pix_fmt yuv420p -shortest "{mp4_file}"' subprocess.run(command, shell=True) return mp4_file except Exception as e: @@ -42,16 +47,22 @@ def convert_to_mp4(mp3_file): return None def convert_to_text(mp3_file): - command = f'./ffmpeg -i "{mp3_file}" output_audio.wav' - subprocess.run(command, shell=True) - r = sr.Recognizer() - # Load the audio file - with sr.AudioFile("output_audio.wav") as source: - data = r.record(source) - # Convert speech to text - text = r.recognize_google(data) - os.remove("output_audio.wav") - return (text) + print(mp3_file) + try: + command = f'ffmpeg -i "{mp3_file}" output_audio.wav' + subprocess.run(command, shell=True) + r = sr.Recognizer() + # Load the audio file + with sr.AudioFile("output_audio.wav") as source: + data = r.record(source) + # Convert speech to text + text = r.recognize_google(data) + os.remove("output_audio.wav") + return (text) + except Exception as e: + print(f"Error during conversion: {e}") + return "" + ## upload to discord