englissi commited on
Commit
564910c
·
verified ·
1 Parent(s): ebb2d0b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -7
app.py CHANGED
@@ -10,10 +10,10 @@ def text_to_speech(prompt):
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
  # 만약 스테레오라면 모노로 변환 (채널 평균)
@@ -25,17 +25,21 @@ def text_to_speech(prompt):
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
 
33
  with gr.Blocks() as demo:
34
  gr.Markdown("## Bulgarian Text-to-Speech (TTS)")
35
- input_prompt = gr.Textbox(label="Enter a prompt in Bulgarian:")
36
- output_audio = gr.Audio(label="Generated Speech", type="numpy")
 
 
37
  generate_button = gr.Button("Generate Speech")
38
 
39
  generate_button.click(text_to_speech, inputs=input_prompt, outputs=output_audio)
40
 
41
- demo.launch()
 
 
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
  # 만약 스테레오라면 모노로 변환 (채널 평균)
 
25
  samples = samples.astype(np.float32) / 32768.0
26
  sample_rate = sound.frame_rate
27
 
28
+ # 임시로 생성한 mp3 파일 삭제
29
  os.remove(audio_file)
30
 
31
+ # gr.Audio(type="numpy")는 (numpy_array, sample_rate) 튜플을 기대합니다.
32
  return samples, sample_rate
33
 
34
  with gr.Blocks() as demo:
35
  gr.Markdown("## Bulgarian Text-to-Speech (TTS)")
36
+ with gr.Row():
37
+ input_prompt = gr.Textbox(label="Enter a prompt in Bulgarian:")
38
+ # type을 "numpy"로 설정하여 numpy 배열을 사용합니다.
39
+ output_audio = gr.Audio(label="Generated Speech", type="numpy")
40
  generate_button = gr.Button("Generate Speech")
41
 
42
  generate_button.click(text_to_speech, inputs=input_prompt, outputs=output_audio)
43
 
44
+ if __name__ == "__main__":
45
+ demo.launch()