limit max sentences allowed to infer
Browse files
app.py
CHANGED
@@ -10,6 +10,7 @@ from scipy.io.wavfile import write, read
|
|
10 |
from pydub import AudioSegment
|
11 |
|
12 |
file_upload_available = os.environ.get("ALLOW_FILE_UPLOAD")
|
|
|
13 |
|
14 |
import json
|
15 |
with open("characters.json", "r") as file:
|
@@ -151,8 +152,17 @@ def infer(prompt, input_wav_file, clean_audio, hidden_numpy_audio):
|
|
151 |
|
152 |
# Move the WAV file to the new directory
|
153 |
shutil.move(source_path, os.path.join(destination_path, f"{file_name}.wav"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
154 |
|
155 |
-
tts.tts_to_file(text=
|
156 |
file_path="output.wav",
|
157 |
voice_dir="bark_voices/",
|
158 |
speaker=f"{file_name}")
|
@@ -169,8 +179,17 @@ def infer(prompt, input_wav_file, clean_audio, hidden_numpy_audio):
|
|
169 |
return "output.wav", tts_video, gr.update(value=f"bark_voices/{file_name}/{contents[1]}", visible=True), gr.Group.update(visible=True), destination_path
|
170 |
|
171 |
def infer_from_c(prompt, c_name):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
172 |
|
173 |
-
tts.tts_to_file(text=
|
174 |
file_path="output.wav",
|
175 |
voice_dir="examples/library/",
|
176 |
speaker=f"{c_name}")
|
@@ -303,7 +322,7 @@ with gr.Blocks(css=css) as demo:
|
|
303 |
with gr.Column():
|
304 |
prompt = gr.Textbox(
|
305 |
label = "Text to speech prompt",
|
306 |
-
info = "One or two sentences at a time is better*",
|
307 |
placeholder = "Hello friend! How are you today?",
|
308 |
elem_id = "tts-prompt"
|
309 |
)
|
|
|
10 |
from pydub import AudioSegment
|
11 |
|
12 |
file_upload_available = os.environ.get("ALLOW_FILE_UPLOAD")
|
13 |
+
MAX_NUMBER_SENTENCES = 10
|
14 |
|
15 |
import json
|
16 |
with open("characters.json", "r") as file:
|
|
|
152 |
|
153 |
# Move the WAV file to the new directory
|
154 |
shutil.move(source_path, os.path.join(destination_path, f"{file_name}.wav"))
|
155 |
+
|
156 |
+
# Split the text into sentences based on common punctuation marks
|
157 |
+
sentences = re.split(r'(?<=[.!?])\s+', prompt)
|
158 |
+
|
159 |
+
# Keep only the first MAX_NUMBER_SENTENCES sentences
|
160 |
+
first_nb_sentences = sentences[:MAX_NUMBER_SENTENCES]
|
161 |
+
|
162 |
+
# Join the selected sentences back into a single string
|
163 |
+
limited_prompt = ' '.join(first_nb_sentences)
|
164 |
|
165 |
+
tts.tts_to_file(text=limited_prompt,
|
166 |
file_path="output.wav",
|
167 |
voice_dir="bark_voices/",
|
168 |
speaker=f"{file_name}")
|
|
|
179 |
return "output.wav", tts_video, gr.update(value=f"bark_voices/{file_name}/{contents[1]}", visible=True), gr.Group.update(visible=True), destination_path
|
180 |
|
181 |
def infer_from_c(prompt, c_name):
|
182 |
+
|
183 |
+
# Split the text into sentences based on common punctuation marks
|
184 |
+
sentences = re.split(r'(?<=[.!?])\s+', prompt)
|
185 |
+
|
186 |
+
# Keep only the first MAX_NUMBER_SENTENCES sentences
|
187 |
+
first_nb_sentences = sentences[:MAX_NUMBER_SENTENCES]
|
188 |
+
|
189 |
+
# Join the selected sentences back into a single string
|
190 |
+
limited_prompt = ' '.join(first_nb_sentences)
|
191 |
|
192 |
+
tts.tts_to_file(text=limited_prompt,
|
193 |
file_path="output.wav",
|
194 |
voice_dir="examples/library/",
|
195 |
speaker=f"{c_name}")
|
|
|
322 |
with gr.Column():
|
323 |
prompt = gr.Textbox(
|
324 |
label = "Text to speech prompt",
|
325 |
+
info = "One or two sentences at a time is better* (max: 10)",
|
326 |
placeholder = "Hello friend! How are you today?",
|
327 |
elem_id = "tts-prompt"
|
328 |
)
|