Spaces:
Runtime error
Runtime error
File size: 1,520 Bytes
710506c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
import pytube
from moviepy.editor import VideoFileClip
import pywhisper
import os
def download_video(url):
video = pytube.YouTube(url)
stream = video.streams.get_by_itag(18)
stream.download()
return stream.default_filename
def convert_to_mp3(filename):
clip = VideoFileClip(filename)
clip.audio.write_audiofile(filename[:-4] + ".mp3")
clip.close()
def AudiotoText(filename):
model = pywhisper.load_model("base")
result = model.transcribe(filename)
print(result["text"])
sonuc = result["text"]
return sonuc
def main(url):
print('''
This tool will convert Youtube videos to mp3 files and then transcribe them to text using Whisper.
''')
print("Downloading video... Please wait.")
try:
filename = download_video(url)
print("Downloaded video as " + filename)
except:
print("Not a valid link..")
return
try:
convert_to_mp3(filename)
print("Converted video to mp3")
except:
print("Error converting video to mp3")
return
try:
model = pywhisper.load_model("base")
result = model.transcribe(filename[:-4] + ".mp3")
print(result["text"])
result = result["text"]
os.remove(filename)
os.remove(filename[:-4] + ".mp3")
print("Removed video and audio files")
print("Done!")
return result
except:
print("Error transcribing audio to text")
return
if __name__ == "__main__":
main()
|