url = "https://speech-dubbing.p.rapidapi.com/get_timestamp"
def get_transcription():
url = "https://elevenlabs-dubbing1.p.rapidapi.com/get_transcription"
files = { "audio_file": open('test_speech.mp3', 'rb') }
payload = {
"spoken_language": "en", # Please use the ISO 3166-1 alpha-2 code, you can access the list at this link: "https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes"
"voice_id": "21m00Tcm4TlvDq8ikWAM", # the available "voice_id" are visible at the "get_voices" endpoint, which will return all the voices with their id.
"elevenlabs_api_key": "YOUR_ELEVENLABS_API_KEY"
}
headers = {
"X-RapidAPI-Key": "YOUR_RAPID_API_KEY",
"X-RapidAPI-Host": "elevenlabs-dubbing1.p.rapidapi.com"
}
response = requests.post(url, data=payload, files=files, headers=headers)
return json.dump(response.json()
transcription = get_transcription()
def translate_transcription(transcription):
url = "https://elevenlabs-dubbing1.p.rapidapi.com/translate_transcription"
querystring = {"target_language":"es"}# Please use the ISO 3166-1 alpha-2 code, you can access the list at this link: "https://fr.wikipedia.org/wiki/ISO_3166-1"
payload = transcription
headers = {
"content-type": "application/json",
"X-RapidAPI-Key": "YOUR_RAPID_API_KEY",
"X-RapidAPI-Host": "elevenlabs-dubbing1.p.rapidapi.com"
}
response = requests.post(url, json=payload, headers=headers, params=querystring)
return response.json()
translated_transcription = translate_transcription(transcription=transcription)
def dub(transcription):
url = "https://elevenlabs-dubbing1.p.rapidapi.com/dubbing"
payload = transcription
headers = {
"content-type": "application/json",
"X-RapidAPI-Key": "YOUR_RAPID_API_KEY",
"X-RapidAPI-Host": "elevenlabs-dubbing1.p.rapidapi.com"
}
response = requests.post(url, json=payload, headers=headers)
with open("output.mp3", "wb") as file:
file.write(response.content)
dub(transcription=translated_transcription)
> Now you can listen to dubbed audio in another language.