How to use synthesized voice over Twilio Programmable Voice

192 Views Asked by At

New to Twilio, and I'm trying to integrate real-time voice clones (https://github.com/CorentinJ) over voice-SDK/programmable-voice. Can someone please suggest how to use my synthesized voice-over in a phone call (for example, instead of available voices through Polly)? If there are any code snippets (preferably in Python) that you could help provide, it's deeply appreciated.

1

There are 1 best solutions below

0
On

Here's an example of how you can use the Twilio SDK to make a phone call with a custom voice. In this case, you would use the verb to play an audio file that you've generated with your voice clone.

First, you need to host your generated audio file somewhere accessible via a URL. This could be a server you control, or a service like Amazon S3. Once you have the URL of the audio file, you can use it in the Twilio SDK.

from twilio.rest import Client
from twilio.twiml.voice_response import VoiceResponse

# Your Twilio credentials
account_sid = 'your_account_sid'
auth_token = 'your_auth_token'

# Initialize the Twilio client
client = Client(account_sid, auth_token)

# The phone numbers involved in the call
to_number = 'number_to_call'
from_number = 'your_twilio_number'

# The URL of your audio file
audio_url = 'http://example.com/path/to/your/audio/file.mp3'

# Create a new VoiceResponse object
response = VoiceResponse()

# Add a Play verb to the response with the URL of your audio file
response.play(audio_url)

# Convert the response to XML
twiml = str(response)

# Make the call
call = client.calls.create(
    twiml=twiml,
    to=to_number,
    from_=from_number
)

print(call.sid)

This code will initiate a phone call from your Twilio number to the specified number. When the call is answered, it will play your audio file.