mrfakename commited on
Commit
e2e4977
1 Parent(s): a2dc6b8

Voice cloning!

Browse files
Files changed (1) hide show
  1. app.py +21 -14
app.py CHANGED
@@ -5,16 +5,10 @@ import torch
5
  theme = gr.themes.Base(
6
  font=[gr.themes.GoogleFont('Libre Franklin'), gr.themes.GoogleFont('Public Sans'), 'system-ui', 'sans-serif'],
7
  )
8
- voices = {
9
- 'angie': styletts2importable.compute_style('voices/angie.wav'),
10
- 'daniel': styletts2importable.compute_style('voices/daniel.wav'),
11
- 'dotrice': styletts2importable.compute_style('voices/dotrice.wav'),
12
- 'lj': styletts2importable.compute_style('voices/lj.wav'),
13
- 'mouse': styletts2importable.compute_style('voices/mouse.wav'),
14
- 'pat': styletts2importable.compute_style('voices/pat.wav'),
15
- 'tom': styletts2importable.compute_style('voices/tom.wav'),
16
- 'william': styletts2importable.compute_style('voices/william.wav'),
17
- }
18
  def synthesize(text, voice):
19
  if text.strip() == "":
20
  raise gr.Error("You must enter some text")
@@ -22,6 +16,12 @@ def synthesize(text, voice):
22
  raise gr.Error("Text must be under 500 characters")
23
  v = voice.lower()
24
  return (24000, styletts2importable.inference(text, voices[v], alpha=0.3, beta=0.7, diffusion_steps=7, embedding_scale=1))
 
 
 
 
 
 
25
  def ljsynthesize(text):
26
  if text.strip() == "":
27
  raise gr.Error("You must enter some text")
@@ -35,11 +35,20 @@ with gr.Blocks() as vctk:
35
  with gr.Row():
36
  with gr.Column(scale=1):
37
  inp = gr.Textbox(label="Text", info="What would you like StyleTTS 2 to read? It works better on full sentences.", interactive=True)
38
- voice = gr.Dropdown(['Angie', 'Daniel', 'Tom', 'LJ', 'Pat', 'Tom', 'Dotrice', 'Mouse', 'William'], label="Voice", info="Select a voice. We use some voices from Tortoise TTS.", value='Tom', interactive=True)
39
  with gr.Column(scale=1):
40
  btn = gr.Button("Synthesize", variant="primary")
41
  audio = gr.Audio(interactive=False, label="Synthesized Audio")
42
  btn.click(synthesize, inputs=[inp, voice], outputs=[audio], concurrency_limit=4)
 
 
 
 
 
 
 
 
 
43
  with gr.Blocks() as lj:
44
  with gr.Row():
45
  with gr.Column(scale=1):
@@ -57,11 +66,9 @@ A free demo of StyleTTS 2. Not affiliated with the StyleTTS 2 Authors.
57
 
58
  **Before using this demo, you agree to inform the listeners that the speech samples are synthesized by the pre-trained models, unless you have the permission to use the voice you synthesize. That is, you agree to only use voices whose speakers grant the permission to have their voice cloned, either directly or by license before making synthesized voices public, or you have to publicly announce that these voices are synthesized if you do not have the permission to use these voices.**
59
 
60
- This space does NOT allow voice cloning. We use some default voice from Tortoise TTS instead.
61
-
62
  Is there a long queue on this space? Duplicate it and add a GPU to skip the wait!""")
63
  gr.DuplicateButton("Duplicate Space")
64
- gr.TabbedInterface([vctk, lj], ['Multi-Voice', 'LJSpeech'])
65
  if __name__ == "__main__":
66
  demo.queue(api_open=False, max_size=15).launch(show_api=False)
67
 
 
5
  theme = gr.themes.Base(
6
  font=[gr.themes.GoogleFont('Libre Franklin'), gr.themes.GoogleFont('Public Sans'), 'system-ui', 'sans-serif'],
7
  )
8
+ voicelist = ['f-us-1', 'f-us-2', 'f-us-3', 'f-us-4', 'm-us-1', 'm-us-2', 'm-us-3', 'm-us-4']
9
+ voices = {}
10
+ for v in voicelist:
11
+ voices[v] = styletts2importable.compute_style(f'voices/{v}.wav')
 
 
 
 
 
 
12
  def synthesize(text, voice):
13
  if text.strip() == "":
14
  raise gr.Error("You must enter some text")
 
16
  raise gr.Error("Text must be under 500 characters")
17
  v = voice.lower()
18
  return (24000, styletts2importable.inference(text, voices[v], alpha=0.3, beta=0.7, diffusion_steps=7, embedding_scale=1))
19
+ def clsynthesize(text, voice):
20
+ if text.strip() == "":
21
+ raise gr.Error("You must enter some text")
22
+ if len(text) > 500:
23
+ raise gr.Error("Text must be under 500 characters")
24
+ return (24000, styletts2importable.inference(text, styletts2importable.compute_style(voice), alpha=0.3, beta=0.7, diffusion_steps=7, embedding_scale=1))
25
  def ljsynthesize(text):
26
  if text.strip() == "":
27
  raise gr.Error("You must enter some text")
 
35
  with gr.Row():
36
  with gr.Column(scale=1):
37
  inp = gr.Textbox(label="Text", info="What would you like StyleTTS 2 to read? It works better on full sentences.", interactive=True)
38
+ voice = gr.Dropdown(voicelist, label="Voice", info="Select a default voice.", value='m-us-1', interactive=True)
39
  with gr.Column(scale=1):
40
  btn = gr.Button("Synthesize", variant="primary")
41
  audio = gr.Audio(interactive=False, label="Synthesized Audio")
42
  btn.click(synthesize, inputs=[inp, voice], outputs=[audio], concurrency_limit=4)
43
+ with gr.Blocks() as clone:
44
+ with gr.Row():
45
+ with gr.Column(scale=1):
46
+ clinp = gr.Textbox(label="Text", info="What would you like StyleTTS 2 to read? It works better on full sentences.", interactive=True)
47
+ clvoice = gr.Audio(label="Voice", info="Select a voice.", value='Tom', interactive=True)
48
+ with gr.Column(scale=1):
49
+ clbtn = gr.Button("Synthesize", variant="primary")
50
+ claudio = gr.Audio(interactive=False, label="Synthesized Audio")
51
+ clbtn.click(clsynthesize, inputs=[clinp, clvoice], outputs=[claudio], concurrency_limit=4)
52
  with gr.Blocks() as lj:
53
  with gr.Row():
54
  with gr.Column(scale=1):
 
66
 
67
  **Before using this demo, you agree to inform the listeners that the speech samples are synthesized by the pre-trained models, unless you have the permission to use the voice you synthesize. That is, you agree to only use voices whose speakers grant the permission to have their voice cloned, either directly or by license before making synthesized voices public, or you have to publicly announce that these voices are synthesized if you do not have the permission to use these voices.**
68
 
 
 
69
  Is there a long queue on this space? Duplicate it and add a GPU to skip the wait!""")
70
  gr.DuplicateButton("Duplicate Space")
71
+ gr.TabbedInterface([vctk, clone, lj], ['Multi-Voice', 'Voice Cloning', 'LJSpeech'])
72
  if __name__ == "__main__":
73
  demo.queue(api_open=False, max_size=15).launch(show_api=False)
74