Update app.py
Browse files
app.py
CHANGED
@@ -7,9 +7,11 @@ import tempfile
|
|
7 |
|
8 |
def text_to_speech(text, language):
|
9 |
if not text:
|
10 |
-
|
|
|
11 |
if not language:
|
12 |
-
|
|
|
13 |
|
14 |
try:
|
15 |
tts = gTTS(text=text, lang=language)
|
@@ -17,12 +19,15 @@ def text_to_speech(text, language):
|
|
17 |
tts.save(fp.name)
|
18 |
sound = AudioSegment.from_file(fp.name, format="mp3")
|
19 |
samples = np.array(sound.get_array_of_samples())
|
|
|
|
|
20 |
if sound.channels == 2:
|
21 |
samples = samples.reshape((-1, 2))
|
22 |
-
|
23 |
-
return samples
|
24 |
except Exception as e:
|
25 |
-
|
|
|
26 |
|
27 |
interface = gr.Interface(
|
28 |
fn=text_to_speech,
|
|
|
7 |
|
8 |
def text_to_speech(text, language):
|
9 |
if not text:
|
10 |
+
print("No text provided")
|
11 |
+
return np.array([]), 22050
|
12 |
if not language:
|
13 |
+
print("No language selected")
|
14 |
+
return np.array([]), 22050
|
15 |
|
16 |
try:
|
17 |
tts = gTTS(text=text, lang=language)
|
|
|
19 |
tts.save(fp.name)
|
20 |
sound = AudioSegment.from_file(fp.name, format="mp3")
|
21 |
samples = np.array(sound.get_array_of_samples())
|
22 |
+
if samples.size == 0:
|
23 |
+
print("No audio data generated")
|
24 |
if sound.channels == 2:
|
25 |
samples = samples.reshape((-1, 2))
|
26 |
+
print(f"Samples: {samples[:10]}") # Print the first 10 samples to diagnose
|
27 |
+
return samples, sound.frame_rate
|
28 |
except Exception as e:
|
29 |
+
print(f"Error: {str(e)}")
|
30 |
+
return np.array([]), 22050
|
31 |
|
32 |
interface = gr.Interface(
|
33 |
fn=text_to_speech,
|