Blane187 commited on
Commit
a3ed77f
·
verified ·
1 Parent(s): 07547cc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -19
app.py CHANGED
@@ -7,17 +7,15 @@ import uuid
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
-
16
  ASSEMBLYAI_API = os.environ.get("ASSEMBLYAI_API")
17
 
18
  def voice_to_voice(audio_file):
19
  transcript = transcribe_audio(audio_file)
20
- if transcript.status == aai.TranscriptStatus.error:
21
  raise gr.Error(transcript.error)
22
  else:
23
  transcript = transcript.text
@@ -33,7 +31,7 @@ def voice_to_voice(audio_file):
33
  return tuple(generated_audio_paths + list_translations)
34
 
35
  def transcribe_audio(audio_file):
36
- aai.settings.api_key = ELEVENLABS_API
37
  transcriber = aai.Transcriber()
38
  transcript = transcriber.transcribe(audio_file)
39
  return transcript
@@ -73,8 +71,6 @@ def text_to_speech(text):
73
 
74
  return save_file_path
75
 
76
-
77
-
78
  def download_audio(url):
79
  ydl_opts = {
80
  'format': 'bestaudio/best',
@@ -94,36 +90,34 @@ def download_audio(url):
94
 
95
  return sample_rate, audio_array
96
 
97
-
98
  with gr.Blocks() as demo:
99
- gr.Markdown("## audio Translator")
100
  gr.Markdown(
101
- f"""
102
  The API Key you need:
103
- (AssemblyAI API key)[https://www.assemblyai.com/?utm_source=youtube&utm_medium=referral&utm_campaign=yt_mis_66]<br>
104
- (Elevenlabs API key)[https://elevenlabs.io/]<br>
105
  Note: you need at least 30 minutes of a voice recording of yourself for the *Professional voice cloning. But there is also a simpler voice cloning option that only requires 30 seconds of voice recording. *Professional voice cloning is a paid feature.
106
-
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
 
125
  output_components = []
126
- languages = ["Turkish", "Swedish", "Russian", "German", "Spanish", "Japanese", "indonesian"]
127
 
128
  for lang in languages:
129
  with gr.Group():
 
7
  from elevenlabs import VoiceSettings
8
  from elevenlabs.client import ElevenLabs
9
  from pathlib import Path
10
+ from scipy.io.wavfile import write, read
 
11
  import yt_dlp
12
 
13
  ELEVENLABS_API = os.environ.get("ELEVENLABS_API")
 
14
  ASSEMBLYAI_API = os.environ.get("ASSEMBLYAI_API")
15
 
16
  def voice_to_voice(audio_file):
17
  transcript = transcribe_audio(audio_file)
18
+ if transcript.status == 'error':
19
  raise gr.Error(transcript.error)
20
  else:
21
  transcript = transcript.text
 
31
  return tuple(generated_audio_paths + list_translations)
32
 
33
  def transcribe_audio(audio_file):
34
+ aai.settings.api_key = ASSEMBLYAI_API
35
  transcriber = aai.Transcriber()
36
  transcript = transcriber.transcribe(audio_file)
37
  return transcript
 
71
 
72
  return save_file_path
73
 
 
 
74
  def download_audio(url):
75
  ydl_opts = {
76
  'format': 'bestaudio/best',
 
90
 
91
  return sample_rate, audio_array
92
 
 
93
  with gr.Blocks() as demo:
94
+ gr.Markdown("## Audio Translator")
95
  gr.Markdown(
96
+ """
97
  The API Key you need:
98
+ [AssemblyAI API key](https://www.assemblyai.com/?utm_source=youtube&utm_medium=referral&utm_campaign=yt_mis_66)<br>
99
+ [Elevenlabs API key](https://elevenlabs.io/)<br>
100
  Note: you need at least 30 minutes of a voice recording of yourself for the *Professional voice cloning. But there is also a simpler voice cloning option that only requires 30 seconds of voice recording. *Professional voice cloning is a paid feature.
 
101
  """
102
  )
103
  audio_input = gr.Audio(type="filepath", show_download_button=True)
104
+ with gr.Accordion("Inputs by Link", open=False):
105
  with gr.Row():
106
  link = gr.Textbox(
107
+ label="Link",
108
+ placeholder="Paste the link here",
109
+ interactive=True
110
  )
111
  download_button = gr.Button(
112
  "Download!",
113
+ variant="primary"
114
  )
115
  download_button.click(download_audio, [link], [audio_input])
116
  submit = gr.Button("Submit", variant="primary")
117
  clear_button = gr.ClearButton(audio_input, "Clear")
118
 
119
  output_components = []
120
+ languages = ["Turkish", "Swedish", "Russian", "German", "Spanish", "Japanese", "Indonesian"]
121
 
122
  for lang in languages:
123
  with gr.Group():