Pranjal12345 commited on
Commit
bd104fa
·
1 Parent(s): e9c4729

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -25
app.py CHANGED
@@ -5,8 +5,7 @@ import torchaudio
5
  import time
6
  from datetime import datetime
7
  from tortoise.api import TextToSpeech
8
- from tortoise.utils.text import split_and_recombine_text
9
- from tortoise.utils.audio import load_audio, load_voice, load_voices
10
 
11
  VOICE_OPTIONS = [
12
  "angie",
@@ -17,22 +16,12 @@ VOICE_OPTIONS = [
17
 
18
  def inference(
19
  text,
20
- script,
21
  voice,
22
  voice_b,
23
- seed,
24
- split_by_newline,
25
  ):
26
- if text is None or text.strip() == "":
27
- with open(script.name) as f:
28
- text = f.read()
29
- if text.strip() == "":
30
- raise gr.Error("Please provide either text or script file with content.")
31
 
32
- if split_by_newline == "Yes":
33
- texts = list(filter(lambda x: x.strip() != "", text.split("\n")))
34
- else:
35
- texts = split_and_recombine_text(text)
36
 
37
  voices = [voice]
38
  if voice_b != "disabled":
@@ -58,9 +47,10 @@ def inference(
58
  def main():
59
  title = "Tortoise TTS "
60
 
61
- label="Text (Provide either text, or upload a newline separated text file below):",
 
 
62
  )
63
- script = gr.File(label="Upload a text file")
64
 
65
  voice = gr.Dropdown(
66
  VOICE_OPTIONS, value="jane_eyre", label="Select voice:", type="value"
@@ -71,24 +61,26 @@ def main():
71
  label="(Optional) Select second voice:",
72
  type="value",
73
  )
74
- split_by_newline = gr.Radio(
75
- ["Yes", "No"],
76
- label="Split by newline (If [No], it will automatically try to find relevant splits):",
77
- type="value",
78
- value="No",
79
- )
80
 
81
  output_audio = gr.Audio(label="streaming audio:", streaming=True, autoplay=True)
82
  interface = gr.Interface(
83
  fn=inference,
84
  inputs=[
85
  text,
86
- script,
87
  voice,
88
  voice_b,
89
- split_by_newline,
90
  ],
91
  title=title,
92
  outputs=[output_audio],
93
  )
94
- interface.queue().launch()
 
 
 
 
 
 
 
 
 
 
 
5
  import time
6
  from datetime import datetime
7
  from tortoise.api import TextToSpeech
8
+ from tortoise.utils.audio import load_voice, load_voices
 
9
 
10
  VOICE_OPTIONS = [
11
  "angie",
 
16
 
17
  def inference(
18
  text,
 
19
  voice,
20
  voice_b,
 
 
21
  ):
22
+ # Set split_by_newline to "No" regardless of the user input
 
 
 
 
23
 
24
+ texts = [text]
 
 
 
25
 
26
  voices = [voice]
27
  if voice_b != "disabled":
 
47
  def main():
48
  title = "Tortoise TTS "
49
 
50
+ text = gr.Textbox(
51
+ lines=4,
52
+ label="Text:",
53
  )
 
54
 
55
  voice = gr.Dropdown(
56
  VOICE_OPTIONS, value="jane_eyre", label="Select voice:", type="value"
 
61
  label="(Optional) Select second voice:",
62
  type="value",
63
  )
 
 
 
 
 
 
64
 
65
  output_audio = gr.Audio(label="streaming audio:", streaming=True, autoplay=True)
66
  interface = gr.Interface(
67
  fn=inference,
68
  inputs=[
69
  text,
 
70
  voice,
71
  voice_b,
 
72
  ],
73
  title=title,
74
  outputs=[output_audio],
75
  )
76
+ interface.queue().launch()
77
+
78
+ if __name__ == "__main__":
79
+ tts = TextToSpeech(kv_cache=True, use_deepspeed=True, half=True)
80
+
81
+ with open("Tortoise_TTS_Runs_Scripts.log", "a") as f:
82
+ f.write(
83
+ f"\n\n-------------------------Tortoise TTS Scripts Logs, {datetime.now()}-------------------------\n"
84
+ )
85
+
86
+ main()