Sakalti commited on
Commit
2ff9b99
·
verified ·
1 Parent(s): 5e77049

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -9
app.py CHANGED
@@ -1,7 +1,7 @@
1
  import gradio as gr
2
- import pyttsx3
3
- import tempfile
4
  from pydub import AudioSegment
 
5
 
6
  # テンプレート設定
7
  TEMPLATES = {
@@ -20,19 +20,17 @@ def change_pitch_speed(sound, pitch_factor=1.0, speed_factor=1.0):
20
  return sound
21
 
22
  def read_text(text, template_name, custom_pitch, custom_speed, use_custom):
23
- # テンプレート選択 or カスタム
24
  if use_custom:
25
  pitch = custom_pitch
26
  speed = custom_speed
27
  else:
28
  pitch, speed = TEMPLATES.get(template_name, (1.0, 1.0))
29
 
30
- # 音声合成
31
- engine = pyttsx3.init()
32
  with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as fp:
 
33
  tts_filename = fp.name
34
- engine.save_to_file(text, tts_filename)
35
- engine.runAndWait()
36
 
37
  sound = AudioSegment.from_file(tts_filename)
38
  modified_sound = change_pitch_speed(sound, pitch_factor=pitch, speed_factor=speed)
@@ -54,8 +52,8 @@ iface = gr.Interface(
54
  gr.Checkbox(label="カスタム設定を使う(オンなら上のスライダー反映)", value=False)
55
  ],
56
  outputs=gr.Audio(label="生成された音声"),
57
- title="パラオボール声 読み上げ機 テンプレート版",
58
- description="テンプレートを選ぶか、カスタムでピッチ・速度を指定して、自由に音声を作ろう!"
59
  )
60
 
61
  iface.launch()
 
1
  import gradio as gr
2
+ from gtts import gTTS
 
3
  from pydub import AudioSegment
4
+ import tempfile
5
 
6
  # テンプレート設定
7
  TEMPLATES = {
 
20
  return sound
21
 
22
  def read_text(text, template_name, custom_pitch, custom_speed, use_custom):
 
23
  if use_custom:
24
  pitch = custom_pitch
25
  speed = custom_speed
26
  else:
27
  pitch, speed = TEMPLATES.get(template_name, (1.0, 1.0))
28
 
29
+ # gTTSで音声合成
30
+ tts = gTTS(text=text, lang='ja')
31
  with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as fp:
32
+ tts.save(fp.name)
33
  tts_filename = fp.name
 
 
34
 
35
  sound = AudioSegment.from_file(tts_filename)
36
  modified_sound = change_pitch_speed(sound, pitch_factor=pitch, speed_factor=speed)
 
52
  gr.Checkbox(label="カスタム設定を使う(オンなら上のスライダー反映)", value=False)
53
  ],
54
  outputs=gr.Audio(label="生成された音声"),
55
+ title="パラオボール声 読み上げ機 gTTS版",
56
+ description="gTTSを使ったシンプル読み上げ機。ピッチと速度を自由に変えられます!"
57
  )
58
 
59
  iface.launch()