Spaces:
Runtime error
Runtime error
| import pywhisper | |
| import os | |
| import pytube | |
| def downloadYTVideo(url): | |
| youtubeVideo = pytube.YouTube(url) | |
| audio = youtubeVideo.streams.filter(only_audio=True).first() | |
| out_file = audio.download(output_path='.') | |
| base, ext = os.path.splitext(out_file) | |
| new_file = base + '.mp3' | |
| os.rename(out_file, new_file) | |
| return new_file | |
| def main(link, model): | |
| try: | |
| file = downloadYTVideo(link) | |
| except: | |
| print("Link is broken. Please check it") | |
| return | |
| try: | |
| whisper_model = pywhisper.load_model(model) | |
| res = whisper_model.transcribe(file) | |
| res = res['text'] | |
| os.remove(file) | |
| return res | |
| except: | |
| return | |
| if __name__ == "__main__": | |
| main() | |