soiz1 commited on
Commit
484d808
·
verified ·
1 Parent(s): d7d05a2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -58
app.py CHANGED
@@ -336,65 +336,65 @@ def voice_conversion(source, target, diffusion_steps, length_adjust, inference_c
336
  ).export(format="mp3", bitrate=bitrate).read()
337
  yield mp3_bytes, None
338
 
339
- default_dir = "./default"
340
- reference_files = [
341
- ("四国めたん", "sikokumetan"),
342
- ]
343
 
344
- gallery_items = [[os.path.join(default_dir, f"{filename}.webp"), name] for name, filename in reference_files]
345
- default_reference = os.path.join(default_dir, f"{reference_files[0][1]}.mp3")
346
 
347
- description = ("Zero-shot音声変換モデル(学習不要)。ローカルでの利用方法は[GitHubリポジトリ](https://github.com/Plachtaa/seed-vc)をご覧ください。"
348
- "参考音声が25秒を超える場合、自動的に25秒にクリップされます。"
349
- "また、元音声と参考音声の合計時間が30秒を超える場合、元音声は分割処理されます。")
350
 
351
- # ギャラリーで選択された音声を `voice_conversion` に渡すプロキシ関数
352
- # ギャラリーで選択されたアイテムから名前を抽出
353
- def proxy_voice_conversion(source, selected_gallery_item, diffusion_steps, length_adjust, inference_cfg_rate, f0_condition, auto_f0_adjust, pitch_shift):
354
- if not source or not os.path.isfile(source):
355
- raise ValueError(f"音声ファイルが見つかりません: {source}")
356
-
357
- # 選択されたギャラリーアイテムからファイル名を正しく抽出
358
- if isinstance(selected_gallery_item, list) and len(selected_gallery_item) > 0:
359
- selected_gallery_item = selected_gallery_item[0][0] # ファイル名だけを取り出す
360
-
361
- else:
362
- raise ValueError("無効なギャラリー選択項目です。")
363
-
364
- reference_file = os.path.join(default_dir, f"{selected_gallery_item}.mp3")
365
- if not os.path.isfile(reference_file):
366
- raise ValueError(f"参照音声ファイルが見つかりません: {reference_file}")
367
-
368
-
369
- outputs = list(voice_conversion(source, reference_file, diffusion_steps, length_adjust, inference_cfg_rate, f0_condition, auto_f0_adjust, pitch_shift))
370
-
371
- while len(outputs) < 2:
372
- outputs.append(None)
373
-
374
- return outputs[0], outputs[1]
375
-
376
-
377
- inputs = [
378
- gr.Audio(type="filepath", label="元音声"),
379
- gr.Gallery(label="参照音声を選択", value=gallery_items, columns=5, interactive=True),
380
- gr.Slider(minimum=1, maximum=200, value=10, step=1, label="拡散ステップ数", info="デフォルトは10、50~100が最適な品質"),
381
- gr.Slider(minimum=0.5, maximum=2.0, step=0.1, value=1.0, label="長さ調整", info="1.0未満で速度を上げ、1.0以上で速度を遅くします"),
382
- gr.Slider(minimum=0.0, maximum=1.0, step=0.1, value=0.7, label="推論CFG率", info="わずかな影響があります"),
383
- gr.Checkbox(label="F0条件付きモデルを使用", value=False, info="歌声変換には必須です"),
384
- gr.Checkbox(label="F0自動調整", value=True, info="F0をおおよそ調整して目標音声に合わせます。F0条件付きモデル使用時にのみ有効です"),
385
- gr.Slider(label='音程変換', minimum=-24, maximum=24, step=1, value=0, info="半音単位の音程変換。F0条件付きモデル使用時にのみ有効です"),
386
- ]
387
-
388
- outputs = [
389
- gr.Audio(label="ストリーム出力音声", streaming=True, format='mp3'),
390
- gr.Audio(label="完全出力音声", streaming=False, format='wav')
391
- ]
392
 
393
- gr.Interface(
394
- fn=proxy_voice_conversion,
395
- description=description,
396
- inputs=inputs,
397
- outputs=outputs,
398
- title="Seed Voice Conversion with Reference Gallery",
399
- cache_examples=False,
400
- ).launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
336
  ).export(format="mp3", bitrate=bitrate).read()
337
  yield mp3_bytes, None
338
 
 
 
 
 
339
 
 
 
340
 
 
 
 
341
 
342
+ # 画像とMP3の情報
343
+ image_data = {
344
+ "sikokumetan": {
345
+ "webp": "default/sikokumetan.webp",
346
+ "mp3": "default/sikokumetan.mp3"
347
+ }
348
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
349
 
350
+ def on_image_select(image_name):
351
+ # 画像が選択されたとき、対応するMP3ファイルを返す
352
+ return image_data[image_name]["mp3"]
353
+
354
+ if __name__ == "__main__":
355
+ description = ("Zero-shot音声変換モデル(学習不要)。ローカルでの利用方法は[GitHubリポジトリ](https://github.com/Plachtaa/seed-vc)をご覧ください。"
356
+ "参考音声が25秒を超える場合、自動的に25秒にクリップされます。"
357
+ "また、元音声と参考音声の合計時間が30秒を超える場合、元音声は分割処理されます。")
358
+
359
+ # 入力欄の定義
360
+ inputs = [
361
+ gr.Audio(type="filepath", label="元音声"),
362
+ gr.Audio(type="filepath", label="参考音声"),
363
+ gr.Slider(minimum=1, maximum=200, value=10, step=1, label="拡散ステップ数", info="デフォルトは10、50~100が最適な品質"),
364
+ gr.Slider(minimum=0.5, maximum=2.0, step=0.1, value=1.0, label="長さ調整", info="1.0未満で速度を上げ、1.0以上で速度を遅くします"),
365
+ gr.Slider(minimum=0.0, maximum=1.0, step=0.1, value=0.7, label="推論CFG率", info="わずかな影響があります"),
366
+ gr.Checkbox(label="F0条件付きモデルを使用", value=False, info="歌声変換には必須です"),
367
+ gr.Checkbox(label="F0自動調整", value=True, info="F0をおおよそ調整して目標音声に合わせます。F0条件付きモデル使用時にのみ有効です"),
368
+ gr.Slider(label='音程変換', minimum=-24, maximum=24, step=1, value=0, info="半音単位の音程変換。F0条件付きモデル使用時にのみ有効です"),
369
+ ]
370
+
371
+ examples = [["examples/source/yae_0.wav", "examples/reference/dingzhen_0.wav", 25, 1.0, 0.7, False, True, 0],
372
+ ["examples/source/jay_0.wav", "examples/reference/azuma_0.wav", 25, 1.0, 0.7, True, True, 0],
373
+ ["examples/source/Wiz Khalifa,Charlie Puth - See You Again [vocals]_[cut_28sec].wav",
374
+ "examples/reference/teio_0.wav", 100, 1.0, 0.7, True, False, 0],
375
+ ["examples/source/TECHNOPOLIS - 2085 [vocals]_[cut_14sec].wav",
376
+ "examples/reference/trump_0.wav", 50, 1.0, 0.7, True, False, -12],
377
+ ]
378
+
379
+ outputs = [gr.Audio(label="ストリーム出力音声", streaming=True, format='mp3'),
380
+ gr.Audio(label="完全出力音声", streaming=False, format='wav')]
381
+
382
+ # 画像ギャラリーを追加
383
+ gallery = gr.Gallery(
384
+ value=[gr.Image(image_data["sikokumetan"]["webp"])],
385
+ label="選択した画像に基づく参考音声",
386
+ elem_id="image_gallery",
387
+ interactive=True
388
+ ).style(grid=2)
389
+
390
+ # ギャラリーの選択時にMP3ファイルを更新する処理
391
+ gallery.change(fn=on_image_select, inputs=gallery, outputs=inputs[1]) # 参考音声を更新
392
+
393
+ gr.Interface(fn=voice_conversion,
394
+ description=description,
395
+ inputs=inputs,
396
+ outputs=outputs,
397
+ title="Seed Voice Conversion",
398
+ examples=examples,
399
+ cache_examples=False,
400
+ ).launch()