Blane187 commited on
Commit
90fbf41
1 Parent(s): 1c28f3e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -1
app.py CHANGED
@@ -7,7 +7,9 @@ import uuid
7
  from elevenlabs import VoiceSettings
8
  from elevenlabs.client import ElevenLabs
9
  from pathlib import Path
10
-
 
 
11
 
12
  ELEVENLABS_API = os.environ.get("ELEVENLABS_API")
13
 
@@ -71,6 +73,28 @@ def text_to_speech(text):
71
 
72
  return save_file_path
73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  with gr.Blocks() as demo:
75
  gr.Markdown("## audio Translator")
76
  gr.Markdown(
@@ -83,6 +107,18 @@ with gr.Blocks() as demo:
83
  """
84
  )
85
  audio_input = gr.Audio(type="filepath", show_download_button=True)
 
 
 
 
 
 
 
 
 
 
 
 
86
  submit = gr.Button("Submit", variant="primary")
87
  clear_button = gr.ClearButton(audio_input, "Clear")
88
 
 
7
  from elevenlabs import VoiceSettings
8
  from elevenlabs.client import ElevenLabs
9
  from pathlib import Path
10
+ from scipy.io.wavfile import write
11
+ from scipy.io.wavfile import read
12
+ import yt_dlp
13
 
14
  ELEVENLABS_API = os.environ.get("ELEVENLABS_API")
15
 
 
73
 
74
  return save_file_path
75
 
76
+
77
+
78
+ def download_audio(url):
79
+ ydl_opts = {
80
+ 'format': 'bestaudio/best',
81
+ 'outtmpl': 'ytdl/%(title)s.%(ext)s',
82
+ 'postprocessors': [{
83
+ 'key': 'FFmpegExtractAudio',
84
+ 'preferredcodec': 'wav',
85
+ 'preferredquality': '192',
86
+ }],
87
+ }
88
+
89
+ with yt_dlp.YoutubeDL(ydl_opts) as ydl:
90
+ info_dict = ydl.extract_info(url, download=True)
91
+ file_path = ydl.prepare_filename(info_dict).rsplit('.', 1)[0] + '.wav'
92
+ sample_rate, audio_data = read(file_path)
93
+ audio_array = np.asarray(audio_data, dtype=np.int16)
94
+
95
+ return sample_rate, audio_array
96
+
97
+
98
  with gr.Blocks() as demo:
99
  gr.Markdown("## audio Translator")
100
  gr.Markdown(
 
107
  """
108
  )
109
  audio_input = gr.Audio(type="filepath", show_download_button=True)
110
+ with gr.Accordion("inputs by Link", open = False):
111
+ with gr.Row():
112
+ link = gr.Textbox(
113
+ label = "Link",
114
+ placeholder = "Paste the link here",
115
+ interactive = True
116
+ )
117
+ download_button = gr.Button(
118
+ "Download!",
119
+ variant = "primary"
120
+ )
121
+ download_button.click(download_audio, [link], [audio_input])
122
  submit = gr.Button("Submit", variant="primary")
123
  clear_button = gr.ClearButton(audio_input, "Clear")
124