Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -5,34 +5,28 @@ import numpy as np
|
|
5 |
import os
|
6 |
|
7 |
def text_to_speech(prompt):
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
try:
|
17 |
-
# pydub으로 mp3 파일 불러오기
|
18 |
-
sound = AudioSegment.from_mp3(audio_file)
|
19 |
-
|
20 |
-
# pydub가 제공하는 raw 데이터를 NumPy 배열로 변환 (int16)
|
21 |
-
samples = np.array(sound.get_array_of_samples())
|
22 |
-
|
23 |
-
# 만약 스테레오라면 모노로 변환 (채널 평균)
|
24 |
-
if sound.channels > 1:
|
25 |
-
samples = samples.reshape((-1, sound.channels))
|
26 |
-
samples = samples.mean(axis=1)
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
return samples, sample_rate
|
38 |
|
|
|
5 |
import os
|
6 |
|
7 |
def text_to_speech(prompt):
|
8 |
+
# gTTS를 이용해 Bulgarian 텍스트를 음성으로 변환
|
9 |
+
tts = gTTS(text=prompt, lang="bg")
|
10 |
+
audio_file = "output.mp3"
|
11 |
+
tts.save(audio_file)
|
12 |
+
|
13 |
+
# pydub으로 mp3 파일 불러오기
|
14 |
+
sound = AudioSegment.from_mp3(audio_file)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
+
# pydub가 제공하는 raw 데이터를 NumPy 배열로 변환 (int16)
|
17 |
+
samples = np.array(sound.get_array_of_samples())
|
18 |
+
|
19 |
+
# 만약 스테레오라면 모노로 변환 (채널 평균)
|
20 |
+
if sound.channels > 1:
|
21 |
+
samples = samples.reshape((-1, sound.channels))
|
22 |
+
samples = samples.mean(axis=1)
|
23 |
+
|
24 |
+
# int16 데이터를 float32로 정규화 (범위: [-1.0, 1.0])
|
25 |
+
samples = samples.astype(np.float32) / 32768.0
|
26 |
+
sample_rate = sound.frame_rate
|
27 |
+
|
28 |
+
# 임시 파일 삭제
|
29 |
+
os.remove(audio_file)
|
30 |
|
31 |
return samples, sample_rate
|
32 |
|