lambdaofgod commited on
Commit
9043fad
·
1 Parent(s): 3e2e994

yet another take on ZeroGPU...

Browse files
Files changed (2) hide show
  1. app.py +2 -0
  2. kokoro_tts.py +1 -23
app.py CHANGED
@@ -3,6 +3,7 @@ import requests
3
  from bs4 import BeautifulSoup
4
  from kokoro_tts import generate_audio
5
  import logging
 
6
 
7
 
8
  logging.basicConfig(level=logging.INFO)
@@ -123,6 +124,7 @@ def get_voice_choices(lang_code):
123
  return []
124
 
125
 
 
126
  def text_to_audio(text, lang_code, voice, progress=gr.Progress()):
127
  try:
128
  audio_data = generate_audio(text, voice=voice, progress=progress)
 
3
  from bs4 import BeautifulSoup
4
  from kokoro_tts import generate_audio
5
  import logging
6
+ import spaces
7
 
8
 
9
  logging.basicConfig(level=logging.INFO)
 
124
  return []
125
 
126
 
127
+ @spaces.GPU(duration=60)
128
  def text_to_audio(text, lang_code, voice, progress=gr.Progress()):
129
  try:
130
  audio_data = generate_audio(text, voice=voice, progress=progress)
kokoro_tts.py CHANGED
@@ -4,21 +4,6 @@ import numpy as np
4
  import logging
5
 
6
 
7
- try:
8
- import spaces
9
-
10
- @spaces.GPU(duration=60)
11
- def get_generator(pipeline, text, voice, speed, split_pattern):
12
- return pipeline(text, voice=voice, speed=speed, split_pattern=r"\.")
13
-
14
- logging.info("Running TTS in spaces")
15
- except:
16
- logging.info("Spaces not available")
17
-
18
- def get_generator(pipeline, text, voice, speed, split_pattern):
19
- return pipeline(text, voice=voice, speed=speed, split_pattern=r"\.")
20
-
21
-
22
  pipeline = KPipeline(lang_code="a")
23
  try:
24
  pipeline = pipeline.to("cuda")
@@ -46,7 +31,7 @@ def generate_audio(
46
  Returns:
47
  numpy.ndarray: Combined audio data at 24kHz sample rate
48
  """
49
- generator = get_generator(pipeline, text, voice, speed, split_pattern="\.")
50
 
51
  all_audio = []
52
  segments = list(generator) # Get total number of segments
@@ -65,10 +50,3 @@ def generate_audio(
65
  # Concatenate all audio segments
66
  combined_audio = np.concatenate(all_audio)
67
  return combined_audio
68
-
69
-
70
- if __name__ == "__main__":
71
- # Example usage
72
- sample_text = "Hello world"
73
- audio_data = generate_audio(sample_text)
74
- sf.write("out.wav", audio_data, 24000)
 
4
  import logging
5
 
6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  pipeline = KPipeline(lang_code="a")
8
  try:
9
  pipeline = pipeline.to("cuda")
 
31
  Returns:
32
  numpy.ndarray: Combined audio data at 24kHz sample rate
33
  """
34
+ generator = pipeline(text, voice=voice, speed=speed, split_pattern=r"\.")
35
 
36
  all_audio = []
37
  segments = list(generator) # Get total number of segments
 
50
  # Concatenate all audio segments
51
  combined_audio = np.concatenate(all_audio)
52
  return combined_audio