Azure / Azure/azure-sdk-for-python
**azure-communication-callautomation** RuntimeWarning: coroutine 'CallMediaOperations.start_media_streaming' was never awaited self._call_media_client.start_media_streaming(
- Dominant language
- Python
- Stars
- 5.6k
- Forks
- 3.4k
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 193
Description
- **Package Name**: azure-communication-callautomation
- **Package Version**: 1.4.0b1
- **Operating System**: windows 10
- **Python Version**: 3.10.8
**Describe the bug**
The mediastreaming is not starting after call connected and "Microsoft.Communication.PlayCompleted" using the command await call_connection_client.start_media_streaming(
operation_callback_url=callback_uri,
operation_context="startMediaStreamingContext"
) ----> but it is starting when it is configured early in Mediastreamingoptions setting start_media_streaming =TRUE before answering the call.
**To Reproduce**
Steps to reproduce the behavior:
this is the whole code for reference
```
async def handle_play(call_connection_id, text_to_play, context):
play_source = TextSource(text=text_to_play, voice_name= "en-US-NancyNeural")
await acs_client.get_call_connection(call_connection_id).play_media(
play_source,
operation_context=context)
@app.route("/api/incomingCall", methods=['POST'])
async def incoming_call_handler():
app.logger.info("incoming event data")
for event_dict in await request.json:
global callback_uri,caller_id_latest
event = EventGridEvent.from_dict(event_dict)
app.logger.info("incoming event data --> %s", event.data)
if event.event_type == SystemEventNames.EventGridSubscriptionValidationEventName:
app.logger.info("Validating subscription")
validation_code = event.data['validationCode']
validation_response = {'validationResponse': validation_code}
return Response(response=json.dumps(validation_response), status=200)
elif event.event_type =="Microsoft.Communication.IncomingCall":
app.logger.info("Incoming call received: data=%s",
event.data)
if event.data['from']['kind'] =="phoneNumber":
caller_id = event.data['from']["phoneNumber"]["value"]
else :
caller_id = event.data['from']['rawId']
caller_id_latest = str(caller_id)
app.logger.info("incoming call handler caller id: %s",
caller_id)
incoming_call_context=event.data['incomingCallContext']
guid =uuid.uuid4()
query_parameters = urlencode({"callerId": caller_id})
callback_uri = f"{CALLBACK_EVENTS_URI}/{guid}?{query_parameters}"
parsed_url = urlparse(CALLBACK_EVENTS_URI)
websocket_url = urlunparse(('wss',parsed_url.netloc,'/ws','', '', ''))
app.logger.info("callback url: %s", callback_uri)
app.logger.info("websocket url: %s", websocket_url)
media_streaming_options = MediaStreamingOptions(
transport_url=websocket_url,
transport_type=MediaStreamingTransportType.WEBSOCKET,
content_type=MediaStreamingContentType.AUDIO,
audio_channel_type=MediaStreamingAudioChannelType.MIXED,
start_media_streaming=False,
enable_bidirectional=True,
audio_format=AudioFormat.PCM24_K_MONO)
answer_call_result = await acs_client.answer_call(incoming_call_context=incoming_call_context,
operation_context="incomingCall",
callback_url=callback_uri,
media_streaming=media_streaming_options,cognitive_services_endpoint=cognitiveservices_endpoint_playmsg)
app.logger.info("Answered call for connection id: %s",
answer_call_result.call_connection_id)
return Response(status=200)
@app.route('/api/callbacks/', methods=['POST'])
async def callbacks(contextId):
for event in await request.json:
# Parsing callback events
global call_connection_id,transfer_call_agent,callback_uri
event_data = event['data']
call_connection_id = event_data["callConnectionId"]
app.logger.info(f"Received Event:-> {event['type']}, Correlation Id:-> {event_data['correlationId']}, CallConnectionId:-> {call_connection_id}")
if event['type'] == "Microsoft.Communication.CallConnected":
await handle_play(
call_connection_id=call_connection_id,
text_to_play="Hello how can i help you today?",
context="GetFreeFormText"
)
elif event['type'] == "Microsoft.Communication.PlayCompleted":
call_connection_properties = await acs_client.get_call_connection(call_connection_id).get_call_properties()
call_connection_client = acs_client.get_call_connection(call_connection_id)
await call_connection_client.start_media_streaming(
operation_callback_url=callback_uri,
operation_context="startMediaStreamingContext"
)
media_streaming_subscription = call_connection_properties.media_streaming_subscription
app.logger.info(f"MediaStreamingSubscription:--> {media_streaming_subscription}")
app.logger.info(f"Received CallConnected event for connection id: {call_connection_id}")
app.logger.info("CORRELATION ID:--> %s", event_data["correlationId"])
app.logger.info("CALL CONNECTION ID:--> %s", event_data["callConnectionId"])
elif event['type'] == "Microsoft.Communication.MediaStreamingStarted":
app.logger.info(f"Media streaming content type:--> {event_data['mediaStreamingUpdate']['contentType']}")
app.logger.info(f"Media streaming status:--> {event_data['mediaStreamingUpdate']['mediaStreamingStatus']}")
app.logger.info(f"Media streaming status details:--> {event_data['mediaStreamingUpdate']['mediaStreamingStatusDetails']}")
elif event['type'] == "Microsoft.Communication.MediaStreamingStopped":
app.logger.info(f"Media streaming content type:--> {event_data['mediaStreamingUpdate']['contentType']}")
app.logger.info(f"Media streaming status:--> {event_data['mediaStreamingUpdate']['mediaStreamingStatus']}")
app.logger.info(f"Media streaming status details:--> {event_data['mediaStreamingUpdate']['mediaStreamingStatusDetails']}")
elif event['type'] == "Microsoft.Communication.MediaStreamingFailed":
app.logger.info(f"Code:->{event_data['resultInformation']['code']}, Subcode:-> {event_data['resultInformation']['subCode']}")
app.logger.info(f"Message:->{event_data['resultInformation']['message']}")
elif event['type'] == "Microsoft.Communication.CallDisconnected":
transfer_call_agent = False
pass
return Response(status=200)
# WebSocket.
@app.websocket('/ws')
async def ws():
global transfer_call_agent
print("Client connected to WebSocket")
await init_websocket(websocket)
if not transfer_call_agent:
await start_conversation()
while True:
try:
# Receive data from the client
data = await websocket.receive()
await process_websocket_message_async(data)
except Exception as e:
print(f"WebSocket connection closed: {e}")
break
else:
pass ```
**Expected behavior**
The media streaming should start once the call gets connected and play media is completed.
**Screenshots**
If applicable, add screenshots to help explain your problem.
**Additional context**
Add any other context about the problem here.
Contributor guide
Assessment
This issue has not been assessed yet.