hyl5 commited on
Commit
841984b
·
verified ·
1 Parent(s): 6731b94

Upload Untitled3.ipynb

Browse files
Files changed (1) hide show
  1. Untitled3.ipynb +103 -0
Untitled3.ipynb ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "nbformat": 4,
3
+ "nbformat_minor": 0,
4
+ "metadata": {
5
+ "colab": {
6
+ "provenance": []
7
+ },
8
+ "kernelspec": {
9
+ "name": "python3",
10
+ "display_name": "Python 3"
11
+ },
12
+ "language_info": {
13
+ "name": "python"
14
+ }
15
+ },
16
+ "cells": [
17
+ {
18
+ "cell_type": "code",
19
+ "execution_count": null,
20
+ "metadata": {
21
+ "id": "UwLzq2KIIYlC"
22
+ },
23
+ "outputs": [],
24
+ "source": [
25
+ "import io\n",
26
+ "import os\n",
27
+ "\n",
28
+ "os.system(\"wget -P hubert/ https://huggingface.co/spaces/MarcusSu1216/XingTong/blob/main/hubert/checkpoint_best_legacy_500.pt\")\n",
29
+ "import gradio as gr\n",
30
+ "import librosa\n",
31
+ "import numpy as np\n",
32
+ "import soundfile\n",
33
+ "from inference.infer_tool import Svc\n",
34
+ "import logging\n",
35
+ "\n",
36
+ "logging.getLogger('numba').setLevel(logging.WARNING)\n",
37
+ "logging.getLogger('markdown_it').setLevel(logging.WARNING)\n",
38
+ "logging.getLogger('urllib3').setLevel(logging.WARNING)\n",
39
+ "logging.getLogger('matplotlib').setLevel(logging.WARNING)\n",
40
+ "\n",
41
+ "model = Svc(\"logs/44k/G_99200.pth\", \"configs/config.json\", cluster_model_path=\"logs/44k/kmeans_10000.pt\")\n",
42
+ "\n",
43
+ "def vc_fn(sid, input_audio, vc_transform, auto_f0,cluster_ratio, noise_scale):\n",
44
+ " if input_audio is None:\n",
45
+ " return \"You need to upload an audio\", None\n",
46
+ " sampling_rate, audio = input_audio\n",
47
+ " # print(audio.shape,sampling_rate)\n",
48
+ " duration = audio.shape[0] / sampling_rate\n",
49
+ " if duration > 100:\n",
50
+ " return \"请上传小于100s的音频,需要转换长音频请本地进行转换\", None\n",
51
+ " audio = (audio / np.iinfo(audio.dtype).max).astype(np.float32)\n",
52
+ " if len(audio.shape) > 1:\n",
53
+ " audio = librosa.to_mono(audio.transpose(1, 0))\n",
54
+ " if sampling_rate != 16000:\n",
55
+ " audio = librosa.resample(audio, orig_sr=sampling_rate, target_sr=16000)\n",
56
+ " print(audio.shape)\n",
57
+ " out_wav_path = \"temp.wav\"\n",
58
+ " soundfile.write(out_wav_path, audio, 16000, format=\"wav\")\n",
59
+ " print( cluster_ratio, auto_f0, noise_scale)\n",
60
+ " out_audio, out_sr = model.infer(sid, vc_transform, out_wav_path,\n",
61
+ " cluster_infer_ratio=cluster_ratio,\n",
62
+ " auto_predict_f0=auto_f0,\n",
63
+ " noice_scale=noise_scale\n",
64
+ " )\n",
65
+ " return \"转换成功\", (44100, out_audio.numpy())\n",
66
+ "\n",
67
+ "\n",
68
+ "app = gr.Blocks()\n",
69
+ "with app:\n",
70
+ " with gr.Tabs():\n",
71
+ " with gr.TabItem(\"介绍\"):\n",
72
+ " gr.Markdown(value=\"\"\"\n",
73
+ " 星瞳_Official的语音在线合成,基于so-vits-svc-4.0生成。\\n\n",
74
+ "\n",
75
+ " 使用须知:\\n\n",
76
+ " 1、请使用伴奏和声去除干净的人声素材,时长小于100秒,格式为mp3或wav。\\n\n",
77
+ " 2、去除伴奏推荐使用UVR5软件,B站上有详细教程。\\n\n",
78
+ " 3、条件不支持推荐使用以下几个去伴奏的网站:\\n\n",
79
+ " https://vocalremover.org/zh/\\n\n",
80
+ " https://tuanziai.com/vocal-remover/upload\\n\n",
81
+ " https://www.lalal.ai/zh-hans/\\n\n",
82
+ " 4、在线版服务器为2核16G免费版,转换效率较慢请耐心等待。\\n\n",
83
+ " 5、使用此模型请标注作者:南下扶苏,以及该项目地址。\\n\n",
84
+ " 6、有问题可以在B站私聊我反馈:https://space.bilibili.com/38523418\\n\n",
85
+ " 7、语音模型转换出的音频请勿用于商业化。\n",
86
+ " \"\"\")\n",
87
+ " spks = list(model.spk2id.keys())\n",
88
+ " sid = gr.Dropdown(label=\"音色\", choices=[\"XT4.0\"], value=\"XT4.0\")\n",
89
+ " vc_input3 = gr.Audio(label=\"上传音频(长度建议小于100秒)\")\n",
90
+ " vc_transform = gr.Number(label=\"变调(整数,可以正负,半音数量,升高八度就是12)\", value=0)\n",
91
+ " cluster_ratio = gr.Number(label=\"聚类模型混合比例,0-1之间,默认为0不启用聚类,能提升音色相似度,但会导致咬字下降(如果使用建议0.5左右)\", value=0)\n",
92
+ " auto_f0 = gr.Checkbox(label=\"自动f0预测,配合聚类模型f0预测效果更好,会导致变调功能失效(仅限转换语音,歌声不要勾选此项会究极跑调)\", value=False)\n",
93
+ " noise_scale = gr.Number(label=\"noise_scale 建议不要动,会影响音质,玄学参数\", value=0.4)\n",
94
+ " vc_submit = gr.Button(\"转换\", variant=\"primary\")\n",
95
+ " vc_output1 = gr.Textbox(label=\"Output Message\")\n",
96
+ " vc_output2 = gr.Audio(label=\"Output Audio\")\n",
97
+ " vc_submit.click(vc_fn, [sid, vc_input3, vc_transform,auto_f0,cluster_ratio, noise_scale], [vc_output1, vc_output2])\n",
98
+ "\n",
99
+ " app.launch()\n"
100
+ ]
101
+ }
102
+ ]
103
+ }