fearflixai / narrator.py
LittleLirow's picture
Updated voice generation to direct HTTP request
99500b3
raw
history blame contribute delete
660 Bytes
import requests
import os
CHUNK_SIZE = 1024
url = "https://api.elevenlabs.io/v1/text-to-speech/TxGEqnHWrfWFTfGW9XjX"
def text2voice(prompt, path, key):
headers = {
"Accept": "audio/mpeg",
"Content-Type": "application/json",
"xi-api-key": f"{key}"
}
data = {
"text": f"{prompt}",
"voice_settings": {
"stability": 0,
"similarity_boost": 0
}
}
response = requests.post(url, json=data, headers=headers, stream=True)
with open(path, 'wb') as f:
for chunk in response.iter_content(chunk_size=CHUNK_SIZE):
if chunk:
f.write(chunk)