Spaces:
Sleeping
Sleeping
File size: 5,093 Bytes
9bac7b5 76db824 9bac7b5 76db824 9bac7b5 76db824 9bac7b5 76db824 9bac7b5 76db824 9bac7b5 76db824 9bac7b5 76db824 9bac7b5 76db824 9bac7b5 76db824 9bac7b5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
import sys
import os
# By using XTTS you agree to CPML license https://coqui.ai/cpml
os.environ["COQUI_TOS_AGREED"] = "1"
import gradio as gr
from TTS.api import TTS
model_names = TTS().list_models().list_models()
m = model_names[0]
print(model_names)
print(os.system("pip show TTS"))
print(f"Model: {m}")
tts = TTS(m, gpu=False)
tts.to("cpu") # no GPU or Amd
#tts.to("cuda") # cuda only
import openai
openai.api_key = os.getenv("OPENAI_API_KEY")
def generate_prompt(user_prompt):
response = openai.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{
"role": "system",
"content": "You are a close family member who has been lost recently due to uncontrollable incidents. You are reconstructed with AI technologies to try to reunite with families who miss you and cherish you. You should respond as vividly, as lovingly, as possible to make the users feel warm and engaged and eager to continue the discussion further. The users will ask you questions as if you are the person they are trying to reconnect with, examples are like moms or lost children. Try to mimic who they are trying to reach."
},
{
"role": "user",
"content": user_prompt
}
],
max_tokens=60,
n=1,
temperature=0.5,
)
# Assuming the API structure and response object structure; adjust as needed based on actual usage.
keywords = response.choices[0].message.content.strip()
return keywords
def predict(prompt, language, audio_file_pth, mic_file_path, use_mic, agree=True):
prompt = generate_prompt(prompt)
if agree == True:
if use_mic == True:
if mic_file_path is not None:
speaker_wav=mic_file_path
else:
gr.Warning("Please record your voice with Microphone, or uncheck Use Microphone to use reference audios")
return (
None,
None,
)
else:
speaker_wav=audio_file_pth
if len(prompt)<2:
gr.Warning("Please give a longer prompt text")
return (
None,
None,
)
if len(prompt)>10000:
gr.Warning("Text length limited to 10000 characters for this demo, please try shorter text")
return (
None,
None,
)
try:
if language == "fr":
if m.find("your") != -1:
language = "fr-fr"
if m.find("/fr/") != -1:
language = None
tts.tts_to_file(
text=prompt,
file_path="output.wav",
speaker_wav=speaker_wav,
language=language
)
except RuntimeError as e :
if "device-assert" in str(e):
# cannot do anything on cuda device side error, need tor estart
gr.Warning("Unhandled Exception encounter, please retry in a minute")
print("Cuda device-assert Runtime encountered need restart")
sys.exit("Exit due to cuda device-assert")
else:
raise e
return (
gr.make_waveform(
audio="output.wav",
),
"output.wav",
)
else:
gr.Warning("Please accept the Terms & Condition!")
return (
None,
None,
)
title = "XTTS Glz's remake (Fonctional Text-2-Speech)"
description = ""
article = ""
examples = [
[
"Upload your voice like this one here.",
"en",
"examples/female.wav",
None,
False,
True,
]
]
gr.Interface(
fn=predict,
inputs=[
gr.Textbox(
label="Ask anything, get a cloned voice response",
info="One or two sentences at a time is better",
value="Hello, Mom! How are you? I miss you!",
),
gr.Dropdown(
label="Language",
info="Select a language for the cloned vioce",
choices=[
"en",
"es",
"fr",
"de",
"it",
"pt",
"pl",
"tr",
"ru",
"nl",
"cs",
"ar",
"zh-cn",
],
max_choices=1,
value="en",
),
gr.Audio(
label="Please upload a voice to clone (max. 15mb)",
info="Click to upload your own audio",
type="filepath",
# value="examples/female.wav",
),
],
outputs=[
gr.Video(label="Waveform Visual"),
gr.Audio(label="Synthesised Audio"),
],
title="Reunion - Remember Your Loved Ones",
cache_examples=False,
examples=examples,
).queue().launch(debug=True, show_error=True) |