Closed jcyrio closed 8 months ago
@jcyrio Could you try again on the latest version?
If you can debug and place a breakpoint, we can triage what the request looks like outbound and see why it might be chopping part of it off. I have a suspicion its related to pluralizations, I'll investigate
import telnyx
import json
from flask import Flask, request, Response
import requests
app = Flask(__name__)
telnyx.api_key = 'KEYXX'
TELNYX_API_KEY = 'KEYXX'
@app.route('/webhook', methods=['POST'])
def webhook():
payload = request.data
event = json.loads(payload)
print("Event Received:", payload)
if not event:
print("Received invalid payload")
return Response(status=400)
try:
if event['data']['record_type'] == 'event' and event['data']['event_type'] == 'call.initiated':
call_control_id = event['data']['payload']['call_control_id']
call = telnyx.Call.retrieve(call_control_id)
call.answer()
print("Call answered for call_control_id:", call_control_id)
elif event['data']['record_type'] == 'event' and event['data']['event_type'] == 'call.answered':
call_control_id = event['data']['payload']['call_control_id']
# call = telnyx.Call.retrieve(call_control_id)
# call.speak(payload="I am speaking this text", voice="Polly.Arthur")
# print("Speaking started for call_control_id:", call_control_id)
url = f'https://api.telnyx.com/v2/calls/{call_control_id}/actions/speak'
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer ' + TELNYX_API_KEY
}
data = {
"payload": "Say this on the call",
"payload_type": "text",
"service_level": "premium",
"stop": "current",
"voice": "Polly.Arthur",
"language": "en-GB",
}
response = requests.post(url, headers=headers, json=data)
print(f"Speak requested for call_control_id: {call_control_id}, response status: {response.status_code} {response.text}")
except Exception as e:
print('Error handling event:', str(e))
return Response(status=500)
return Response(status=200)
if __name__ == '__main__':
app.run(debug=True)
Speak requested for call_control_id: v3:qNH9nd0x6oxYlvnHi05WK084CZoo28pLt1dUlYpBna-28-AOJj64Ww, response status: 422 {
"errors": [
{
"code": "90012",
"detail": "The 'voice' parameter Polly.Arthur is not supported, please consult documentation.",
"source": {
"pointer": "/voice"
},
"title": "Invalid value for voice"
}
]
}
This appears to be a bug with the underlying API, as it can be reproduced using the requests http library.
I do not experience the issue when "Polly.Brian" is set as the voice with language as "en-GB" but I can reproduce the error when I set the Polly voice to Arthur with language as "en-GB".
ENGDESK-29171 was internally created for the responsible engineering team to resolve.
We will mark this github issue as resolved once we get confirmation, as it's not an issue with the SDK itself as far as I can see.
The engineering team confirmed that the Arthur voice is not apart of the standard voice offering by Amazon, which is currently the only set of supported voices we offer at this time. Arthur is considered a neural voice.
Reference: https://docs.aws.amazon.com/polly/latest/dg/voicelist.html
The API docs says for call.speak voice:
The gender of the voice used to speak back the text or the specific Amazon Polly voice to be used in the form of Polly.<voice>, e.g. Polly.Brian. All standard Amazon Polly voices are supported.
If I try, for example,
my_call.speak(payload="I am speaking this text", voice="Polly.Arthur")
, I get the following error:error_code=90012 error_detail="The 'voice' parameter Polly.Arthur is not supported, please consult documentation." error_source="{'pointer': '/voice'}" error_title='Invalid value for voice' message='Telnyx API error received'
Using Python 3.11.2 and Telnyx library 2.0.0