| import gradio as gr |
| from pytube import YouTube |
| from moviepy.editor import * |
| import os |
|
|
| def download_audio_as_wav(youtube_url): |
| output_filename = "downloaded_audio" |
| |
| yt = YouTube(youtube_url) |
| audio_stream = yt.streams.filter(only_audio=True).first() |
| audio_file = audio_stream.download(filename='temp_audio.mp4') |
|
|
| |
| clip = AudioFileClip(audio_file) |
| output_path = f"{output_filename}.wav" |
| clip.write_audiofile(output_path) |
|
|
| |
| clip.close() |
| os.remove('temp_audio.mp4') |
| |
| return output_path |
|
|
| |
| iface = gr.Interface( |
| fn=download_audio_as_wav, |
| inputs=[gr.Textbox(label="Enter YouTube Video URL")], |
| outputs=[gr.Audio(label="Downloaded Audio")], |
| title="YouTube Audio Downloader", |
| description="Enter a YouTube video URL to download its audio as a .wav file." |
| ) |
|
|
| |
| iface.launch(debug=True) |
|
|