MCPcopy Create free account
hub / github.com/SparkAudio/Spark-TTS / build_ui

Function build_ui

webui.py:94–221  ·  view source on GitHub ↗
(model_dir, device=0)

Source from the content-addressed store, hash-verified

92
93
94def build_ui(model_dir, device=0):
95
96 # Initialize model
97 model = initialize_model(model_dir, device=device)
98
99 # Define callback function for voice cloning
100 def voice_clone(text, prompt_text, prompt_wav_upload, prompt_wav_record):
101 """
102 Gradio callback to clone voice using text and optional prompt speech.
103 - text: The input text to be synthesised.
104 - prompt_text: Additional textual info for the prompt (optional).
105 - prompt_wav_upload/prompt_wav_record: Audio files used as reference.
106 """
107 prompt_speech = prompt_wav_upload if prompt_wav_upload else prompt_wav_record
108 prompt_text_clean = None if len(prompt_text) < 2 else prompt_text
109
110 audio_output_path = run_tts(
111 text,
112 model,
113 prompt_text=prompt_text_clean,
114 prompt_speech=prompt_speech
115 )
116 return audio_output_path
117
118 # Define callback function for creating new voices
119 def voice_creation(text, gender, pitch, speed):
120 """
121 Gradio callback to create a synthetic voice with adjustable parameters.
122 - text: The input text for synthesis.
123 - gender: 'male' or 'female'.
124 - pitch/speed: Ranges mapped by LEVELS_MAP_UI.
125 """
126 pitch_val = LEVELS_MAP_UI[int(pitch)]
127 speed_val = LEVELS_MAP_UI[int(speed)]
128 audio_output_path = run_tts(
129 text,
130 model,
131 gender=gender,
132 pitch=pitch_val,
133 speed=speed_val
134 )
135 return audio_output_path
136
137 with gr.Blocks() as demo:
138 # Use HTML for centered title
139 gr.HTML('<h1 style="text-align: center;">Spark-TTS by SparkAudio</h1>')
140 with gr.Tabs():
141 # Voice Clone Tab
142 with gr.TabItem("Voice Clone"):
143 gr.Markdown(
144 "### Upload reference audio or recording (上传参考音频或者录音)"
145 )
146
147 with gr.Row():
148 prompt_wav_upload = gr.Audio(
149 sources="upload",
150 type="filepath",
151 label="Choose the prompt audio file, ensuring the sampling rate is no lower than 16kHz.",

Callers 1

webui.pyFile · 0.85

Calls 1

initialize_modelFunction · 0.85

Tested by

no test coverage detected