How do I loop through this routine X number of times where the text on line 7, and the filename on line 13 change every time? Is there a sane way to make a loop of this?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| curl -X 'POST' \ | |
| 'https://api.url.foo/v1/foo/someID' \ | |
| --header 'accept: audio/mpeg' \ | |
| --header 'api-key: somekey' \ | |
| --header 'Content-Type: application/json' \ | |
| --data '{ | |
| "text": "This text will change every time.", | |
| "model_id": "id_v1", | |
| "voice_settings": { | |
| "stability": 0.5, | |
| "similarity_boost": 0.5 | |
| } | |
| }' --output "this_title_will_change.mp3" |
import requests
CHUNK_SIZE = 1024
url = "https://api.elevenlabs.io/v1/text-to-speech/<voice-id>"
headers = {"Accept": "audio/mpeg", "Content-Type": "application/json", "xi-api-key": "<xi-api-key>"}
data = [
{
"text": "Hi! My name is Bella, nice to meet you!",
"model_id": "eleven_monolingual_v1",
"voice_settings": {"stability": 0.5, "similarity_boost": 0.5},
},
{
"text": "A new Hi! My name is Bella, nice to meet you!",
"model_id": "eleven_monolingual_v2",
"voice_settings": {"stability": 0.5, "similarity_boost": 0.5},
},
]
for d in data:
response = requests.post(url, json=d, headers=headers)
model_id = d["model_id"]
with open(f"output_{model_id}.mp3", "wb") as f:
for chunk in response.iter_content(chunk_size=CHUNK_SIZE):
if chunk:
f.write(chunk)import requests
CHUNK_SIZE = 1024
url = "https://api.elevenlabs.io/v1/text-to-speech/<voice-id>"
headers = {"Accept": "audio/mpeg", "Content-Type": "application/json", "xi-api-key": "<xi-api-key>"}
data = [
{
"TEXT1_ABOUT_STEP1": "This is what you do on step 1, you download a Win11 ISO by doing a, b, c",
"TITLE_ABOUT_STEP1": "HowToDownloadWin11ISO.mp3",
},
{
"TEXT2_ABOUT_STEP2": "This is what you do on step 2, you download an Ubuntu ISO by doing a, b, c",
"TITLE_ABOUT_STEP2": "HowToDownloadLUbuntuinuxISO.mp3",
},
{
"TEXT3_ABOUT_STEP3": "This is what you do in step 3 to enable Hyper-V on Windows 11",
"TITLE_ABOUT_STEP3": "HowToSetUpHyper-V.mp3",
},
{
"TEXT4_ABOUT_STEP4": "This is what you do in step 4 to install VMware Player on Windows",
"TITLE_ABOUT_STEP4": "HowToInstallVMwarePlayer.mp3",
},
]
for d in data:
response = requests.post(url, json=d, headers=headers)
model_id = d["model_id"]
with open(f"output_{model_id}.mp3", "wb") as f:
for chunk in response.iter_content(chunk_size=CHUNK_SIZE):
if chunk:
f.write(chunk)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
first
second
third
Just so I understand you mean something like this even though it is manual. Is there a reason you want to do this with curl verses a programming language?