soiz commited on
Commit
c280e59
1 Parent(s): 150d7c2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -67
app.py CHANGED
@@ -1,73 +1,46 @@
1
- import gradio as gr
2
- from rvc import *
 
3
 
4
- initial_md = """
5
 
6
- # MIKU TTS - 5.0.1
 
 
 
7
 
8
- """
 
 
 
 
 
 
 
 
 
 
 
9
 
10
- app = gr.Blocks(theme='NoCrypt/miku')
11
- with app:
12
- gr.Markdown(initial_md)
13
- with gr.Row():
14
- with gr.Column():
15
- model_name = gr.Dropdown(label="Model",choices=models,value=models[0])
16
- f0_key_up = gr.Number(label="Tune",value=6)
17
- with gr.Column():
18
- f0_method = gr.Radio(label="Pitch extraction method (pm: very fast, low quality, rmvpe: a little slow, high quality)",choices=["pm", "rmvpe"], value="rmvpe",visible=False)
19
- index_rate = gr.Slider(minimum=0,maximum=1,label="Index rate",value=1,interactive=True)
20
- protect0 = gr.Slider(minimum=0,maximum=0.5,label="Protect",value=0.33,step=0.01,interactive=True)
21
-
22
-
23
- with gr.Row():
24
- with gr.Column():
25
- tts_voice = gr.Dropdown(
26
- label="Edge-tts speaker (format: language-Country-Name-Gender), make sure the gender matches the model",
27
- choices=tts_voices,
28
- allow_custom_value=False,
29
- value="ja-JP-NanamiNeural-Female",
30
- )
31
- speed = gr.Slider(
32
- minimum=-100,
33
- maximum=100,
34
- label="Speech speed (%)",
35
- value=0,
36
- step=10,
37
- interactive=True,
38
- )
39
- tts_text = gr.Textbox(label="Input Text", value="こんにちは、私の名前は初音ミクです!")
40
- with gr.Column():
41
- but0 = gr.Button("Convert", variant="primary")
42
- info_text = gr.Textbox(label="Output info")
43
- with gr.Column():
44
- with gr.Accordion("Edge Voice", visible=False):
45
- edge_tts_output = gr.Audio(label="Edge Voice", type="filepath")
46
- tts_output = gr.Audio(label="Result")
47
- but0.click(
48
- tts,
49
- [
50
- model_name,
51
- speed,
52
- tts_text,
53
- tts_voice,
54
- f0_key_up,
55
- f0_method,
56
- index_rate,
57
- protect0,
58
- ],
59
- [info_text, edge_tts_output, tts_output],
60
- )
61
- with gr.Row():
62
- examples = gr.Examples(
63
- examples_per_page=100,
64
- examples=[
65
- ["こんにちは、私の名前は初音ミクです!", "ja-JP-NanamiNeural-Female", 6],
66
- ["Hello there. My name is Hatsune Miku!","en-CA-ClaraNeural-Female", 6],
67
- ["Halo. Nama saya Hatsune Miku!","id-ID-GadisNeural-Female", 4],
68
- ["Halo. Jenengku Hatsune Miku!","jv-ID-SitiNeural-Female", 10],
69
- ],
70
- inputs=[tts_text, tts_voice, f0_key_up],
71
  )
72
 
73
- app.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, request, jsonify, send_file
2
+ from rvc import * # 既存のTTSモデルがこのモジュールにあると仮定します
3
+ import os
4
 
5
+ app = Flask(__name__)
6
 
7
+ # モデルの初期化 (必要ならば)
8
+ # Gradio用に定義されていたモデルやパラメータをここで適用
9
+ models = [...] # 実際のモデルのリスト
10
+ tts_voices = [...] # TTS声のリスト
11
 
12
+ @app.route('/tts', methods=['GET'])
13
+ def tts_api():
14
+ try:
15
+ # URLパラメータの取得
16
+ model_name = request.args.get('model_name', default=models[0], type=str)
17
+ f0_key_up = request.args.get('f0_key_up', default=6, type=int)
18
+ f0_method = request.args.get('f0_method', default="rmvpe", type=str)
19
+ index_rate = request.args.get('index_rate', default=1.0, type=float)
20
+ protect0 = request.args.get('protect0', default=0.33, type=float)
21
+ tts_voice = request.args.get('tts_voice', default="ja-JP-NanamiNeural-Female", type=str)
22
+ speed = request.args.get('speed', default=0, type=int)
23
+ tts_text = request.args.get('tts_text', default="こんにちは、私の名前は初音ミクです!", type=str)
24
 
25
+ # Gradioと同じTTS関数を呼び出して、音声を生成
26
+ info_text, edge_tts_output, tts_output = tts(
27
+ model_name, speed, tts_text, tts_voice, f0_key_up, f0_method, index_rate, protect0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  )
29
 
30
+ # 生成された音声ファイルを返す
31
+ if tts_output and os.path.exists(tts_output):
32
+ return send_file(tts_output, as_attachment=True)
33
+
34
+ # エッジTTS出力がある場合はこちらを使用
35
+ if edge_tts_output and os.path.exists(edge_tts_output):
36
+ return send_file(edge_tts_output, as_attachment=True)
37
+
38
+ return jsonify({"error": "Failed to generate TTS output"}), 500
39
+
40
+ except Exception as e:
41
+ # エラーが発生した場合はJSONでエラーを返す
42
+ return jsonify({"error": str(e)}), 400
43
+
44
+
45
+ if __name__ == '__main__':
46
+ app.run(host='0.0.0.0', port=7860)