mirror of
https://github.com/majmongoose/PageBot.git
synced 2024-11-23 21:08:36 -05:00
Multiple
Update gitignore Update to have some more logic
This commit is contained in:
parent
b4d9997fc6
commit
41bb8756fd
5
.gitignore
vendored
5
.gitignore
vendored
@ -1,6 +1,9 @@
|
|||||||
|
# Ignore pycache
|
||||||
|
__pycache__/
|
||||||
# Ignore ffmpeg executable
|
# Ignore ffmpeg executable
|
||||||
ffmpeg
|
ffmpeg
|
||||||
ffprobe
|
ffmpeg.exe
|
||||||
|
output_audio.wav
|
||||||
|
|
||||||
# Ignore secrets file
|
# Ignore secrets file
|
||||||
secrets_file.py
|
secrets_file.py
|
17
pagebot.py
17
pagebot.py
@ -24,17 +24,22 @@ class MyHandler(FileSystemEventHandler):
|
|||||||
print("New MP3!")
|
print("New MP3!")
|
||||||
text = ""
|
text = ""
|
||||||
if secrets_file.speech_to_text:
|
if secrets_file.speech_to_text:
|
||||||
|
print("Converting To Text")
|
||||||
text = convert_to_text(filepath)
|
text = convert_to_text(filepath)
|
||||||
|
print("Converting to MP4")
|
||||||
mp4_file = convert_to_mp4(filepath)
|
mp4_file = convert_to_mp4(filepath)
|
||||||
|
print("Sending to Discord")
|
||||||
client.loop.create_task(upload_to_discord(mp4_file,text))
|
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
|
##convert mp3 to mp4
|
||||||
def convert_to_mp4(mp3_file):
|
def convert_to_mp4(mp3_file):
|
||||||
try:
|
try:
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
mp4_file = os.path.splitext(mp3_file)[0] + '.mp4'
|
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)
|
subprocess.run(command, shell=True)
|
||||||
return mp4_file
|
return mp4_file
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -42,7 +47,9 @@ def convert_to_mp4(mp3_file):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def convert_to_text(mp3_file):
|
def convert_to_text(mp3_file):
|
||||||
command = f'./ffmpeg -i "{mp3_file}" output_audio.wav'
|
print(mp3_file)
|
||||||
|
try:
|
||||||
|
command = f'ffmpeg -i "{mp3_file}" output_audio.wav'
|
||||||
subprocess.run(command, shell=True)
|
subprocess.run(command, shell=True)
|
||||||
r = sr.Recognizer()
|
r = sr.Recognizer()
|
||||||
# Load the audio file
|
# Load the audio file
|
||||||
@ -52,6 +59,10 @@ def convert_to_text(mp3_file):
|
|||||||
text = r.recognize_google(data)
|
text = r.recognize_google(data)
|
||||||
os.remove("output_audio.wav")
|
os.remove("output_audio.wav")
|
||||||
return (text)
|
return (text)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error during conversion: {e}")
|
||||||
|
return ""
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## upload to discord
|
## upload to discord
|
||||||
|
Loading…
Reference in New Issue
Block a user