Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import
|
| 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 |
-
|
| 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()
|