Spaces:
Sleeping
Sleeping
First commit - Use output.wav file
Browse files- .gitignore +2 -0
- __pycache__/main.cpython-311.pyc +0 -0
- flagged/log.csv +2 -0
- main.py +61 -0
.gitignore
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.env
|
| 2 |
+
output.wav
|
__pycache__/main.cpython-311.pyc
ADDED
|
Binary file (627 Bytes). View file
|
|
|
flagged/log.csv
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Text to Speach,Coice your creator,output,flag,username,timestamp
|
| 2 |
+
Hey! Sé que estás buscando algo ,Xavy,,,,2024-04-18 10:12:05.928360
|
main.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from dotenv import load_dotenv
|
| 3 |
+
import gradio as gr
|
| 4 |
+
import requests
|
| 5 |
+
import pathlib
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
load_dotenv()
|
| 9 |
+
KEY_ELEVENLABS = os.getenv('ELEVENLABS_KEY')
|
| 10 |
+
print(KEY_ELEVENLABS)
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def generate_audio(text_input: str, creator: str) -> str:
|
| 14 |
+
CHUNK_SIZE = 1024
|
| 15 |
+
|
| 16 |
+
headers = {
|
| 17 |
+
"Accept": "application/json",
|
| 18 |
+
"xi-api-key": KEY_ELEVENLABS
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
voice_id = ''
|
| 22 |
+
|
| 23 |
+
match creator:
|
| 24 |
+
case 'Roomie':
|
| 25 |
+
voice_id = '2Onew6n5JwT9uEbmTSrO'
|
| 26 |
+
case 'Xavy':
|
| 27 |
+
voice_id = 'cYBsY94mzMC7VpGoVMgr'
|
| 28 |
+
case 'Bella':
|
| 29 |
+
voice_id = 'X9j5sAaRD6aEgBblOUOG'
|
| 30 |
+
|
| 31 |
+
url = f"https://api.elevenlabs.io/v1/text-to-speech/{voice_id}/stream"
|
| 32 |
+
|
| 33 |
+
payload = {
|
| 34 |
+
"text": text_input,
|
| 35 |
+
"model_id": "eleven_monolingual_v1",
|
| 36 |
+
"voice_settings": {
|
| 37 |
+
"stability": 0.5,
|
| 38 |
+
"similarity_boost": 0.8,
|
| 39 |
+
"style": 0.0,
|
| 40 |
+
"use_speaker_boost": False
|
| 41 |
+
}
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
response = requests.post(url, headers=headers, json=payload, stream=True)
|
| 45 |
+
print(response)
|
| 46 |
+
with open('output.wav', 'wb') as f:
|
| 47 |
+
for chunk in response.iter_content(chunk_size=CHUNK_SIZE):
|
| 48 |
+
if chunk:
|
| 49 |
+
f.write(chunk)
|
| 50 |
+
|
| 51 |
+
return f'{pathlib.Path().resolve()}\output.mp3'
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
app = gr.Interface(
|
| 55 |
+
fn=generate_audio,
|
| 56 |
+
inputs=[gr.Textbox(label='Text to Speach'), gr.Dropdown(
|
| 57 |
+
['Roomie', 'Xavy', 'Bella'], label="Coice your creator")],
|
| 58 |
+
outputs=['audio']
|
| 59 |
+
)
|
| 60 |
+
|
| 61 |
+
app.launch()
|