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" # Download YouTube video audio stream yt = YouTube(youtube_url) audio_stream = yt.streams.filter(only_audio=True).first() audio_file = audio_stream.download(filename='temp_audio.mp4') # Convert downloaded audio to .wav format clip = AudioFileClip(audio_file) output_path = f"{output_filename}.wav" clip.write_audiofile(output_path) # Clean up the temporary file clip.close() os.remove('temp_audio.mp4') return output_path # Gradio interface 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." ) # Launch the app iface.launch(debug=True)