Forum Discussion
Issue with Media Playback in Azure Communication Services Using Python
Context: We are building a bot using Azure Communication Services (ACS) and Azure Speech Services to handle phone calls. The bot uses text-to-speech (TTS) to play questions during calls and captures user responses.
What We’ve Done:
- Created an ACS instance and acquired an active phone number.
- Set up an event subscription to handle the callback for incoming calls.
- Integrated Azure Speech Services for TTS using Python.
Achievements:
- Successfully connected calls using ACS.
- Generated TTS audio files for trial questions.
Challenges: Converted TTS audio files are not playing during the call. The playback method does not raise errors, but no audio is heard on the call.
Help Needed:
- Are there specific requirements for media playback using the ACS SDK for Python?
- How can we debug why the audio is not playing despite being hosted on a public URL?
Additional Context:
- Using Python 3.12.6 and the Azure Communication Services Python SDK.
- The audio files are hosted on a local server and accessible via public URLs.
Steps Followed:
- Caller Initiates a Call: Someone calls the phone number linked to my ACS resource.
- ACS Sends an Incoming Call Event: ACS sends a Microsoft.Communication.IncomingCall event to my /calling-events endpoint.
- Application Answers the Call: My Flask app receives the event and answers the call using the incomingCallContext.
- Call Connected Event: Once the call is established, ACS sends a Microsoft.Communication.CallConnected event.
- Start Interaction: I start the conversation by playing a welcome message to the caller.
- Play Audio Messages:
- The excel question text gets converted to speech using Azure text to speech API from Azure speech service
- This converted speech is stored as .wav files
- These .wav files need to be hosted on a publicly accessible URL so that the ACS can access them and play it on call
- Handle User Input: After the question is played, If speech recognition is implemented, the bot listens for and processes the caller's speech input.
- End the Call: After the conversation, the bot plays a goodbye message and hangs up.
- Clean Up: The bot handles the CallDisconnected event to clean up any resources or state.
Code Snippet (Python):
def play_audio(call_connection_id, audio_file_path):
try:
audio_url = f"http://example.com/{audio_file_path}" # Publicly accessible URL
call_connection = call_automation_client.get_call_connection(call_connection_id)
file_source = FileSource(url=audio_url)
call_connection.play_media(play_source=file_source, play_to=True)
print(f"Playing audio: {audio_url}")
except Exception as e:
print(f"Error playing audio: {e}")
- jkhandebharadCopper Contributor
I'm also doing something similar. Azure communication services seems to have lot of problems, even there are issues in documentation. In my case I'm getting one callback event 'Microsoft.Communication.PlayFailed' even I have set by interupt_call_media_operation = false still the operations are barging in on ongoing media. I have currectly 5 open support tickets and support engineers are not giving any timeline.
I don't know what to do...