Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -28,16 +28,19 @@ for name in list_repo_files(repo_id="balacoon/tts"):
|
|
28 |
|
29 |
def text_to_speech(text):
|
30 |
with tempfile.NamedTemporaryFile(delete=False, suffix='.wav') as temp_file:
|
|
|
|
|
|
|
|
|
|
|
31 |
with locker:
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
temp_file.write(np.ascontiguousarray(audio_data))
|
40 |
-
return temp_file.name
|
41 |
|
42 |
def combine_audio_files(audio_files):
|
43 |
combined = AudioSegment.empty()
|
|
|
28 |
|
29 |
def text_to_speech(text):
|
30 |
with tempfile.NamedTemporaryFile(delete=False, suffix='.wav') as temp_file:
|
31 |
+
if len(text) > 1024:
|
32 |
+
# truncate the text
|
33 |
+
text_str = text[:1024]
|
34 |
+
else:
|
35 |
+
text_str = text
|
36 |
with locker:
|
37 |
+
samples = tts.synthesize(text_str, "92")
|
38 |
+
output_file = temp_file.name
|
39 |
+
with wave.open(f"{output_file}", "w") as fp:
|
40 |
+
fp.setparams((1, 2, tts.get_sampling_rate(), len(samples), "NONE", "NONE"))
|
41 |
+
samples = np.ascontiguousarray(samples)
|
42 |
+
fp.writeframes(samples)
|
43 |
+
return output_file
|
|
|
|
|
44 |
|
45 |
def combine_audio_files(audio_files):
|
46 |
combined = AudioSegment.empty()
|