File size: 990 Bytes
c7863c5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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)