Spaces:
Running
Running
Commit
•
36b3e86
1
Parent(s):
c95f2c8
Update app_multi.py
Browse files- app_multi.py +31 -0
app_multi.py
CHANGED
@@ -42,6 +42,37 @@ from infer_pack.models import (
|
|
42 |
)
|
43 |
from vc_infer_pipeline import VC
|
44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
# music search
|
46 |
|
47 |
def auto_search(name):
|
|
|
42 |
)
|
43 |
from vc_infer_pipeline import VC
|
44 |
|
45 |
+
import tempfile
|
46 |
+
from openai import OpenAI
|
47 |
+
|
48 |
+
def tts(text, model, voice, api_key):
|
49 |
+
if api_key == '':
|
50 |
+
raise gr.Error('Please enter your OpenAI API Key')
|
51 |
+
else:
|
52 |
+
try:
|
53 |
+
client = OpenAI(api_key=api_key)
|
54 |
+
|
55 |
+
response = client.audio.speech.create(
|
56 |
+
model=model, # "tts-1","tts-1-hd"
|
57 |
+
voice=voice, # 'alloy', 'echo', 'fable', 'onyx', 'nova', 'shimmer'
|
58 |
+
input=text,
|
59 |
+
)
|
60 |
+
|
61 |
+
except Exception as error:
|
62 |
+
# Handle any exception that occurs
|
63 |
+
raise gr.Error("An error occurred while generating speech. Please check your API key and try again.")
|
64 |
+
print(str(error))
|
65 |
+
|
66 |
+
# Create a temp file to save the audio
|
67 |
+
with tempfile.NamedTemporaryFile(suffix=".mp3", delete=False) as temp_file:
|
68 |
+
temp_file.write(response.content)
|
69 |
+
|
70 |
+
# Get the file path of the temp file
|
71 |
+
temp_file_path = temp_file.name
|
72 |
+
|
73 |
+
return temp_file_path
|
74 |
+
|
75 |
+
|
76 |
# music search
|
77 |
|
78 |
def auto_search(name):
|