Workflow: Receiving Audio by Using the Oracle Radio WebSocket API
Subscribe to a Radio channel, establish decoder state from transmission events, and route server-framed binary audio to the correct channel.
Before You Begin
Open an authenticated WebSocket connection. Follow Subscribing to an Oracle Radio WebSocket Channel to send SUBSCRIBE, and confirm that the channel's subscribed result is true.
Receive Audio
-
Listen for
CHANNEL_BUSY. See Requesting the Oracle Radio WebSocket Talk Floor for the channel, talk-floor holder, priority, and expiration properties in this event. -
When
TRANSMISSION_STARTarrives, discard any stale decoder state for itschanneland create state for the new transmission. The message contract requirestype,channel, anduser; theformat,sampleRate,channels,bitrate, andframeSizedecoder properties are optional. See Starting an Oracle Radio WebSocket Audio Transmission.Before processing binary audio, verify that the event provides enough settings to configure the decoder. If required decoder information is absent, do not infer defaults or decode the channel's packets.
-
For each following binary WebSocket message, read the first 2 bytes as the unsigned, big-endian length of the UTF-8 channel name. Read that many channel-name bytes. Treat all remaining bytes as the original encoded audio packet. See Sending Oracle Radio WebSocket Audio for the server-to-client framed audio layout.
-
Route the packet to the decoder state for the parsed channel. Keep decoder state separate for each channel, and use only the verified decoder settings for the current transmission.
-
When
TRANSMISSION_ENDarrives, finish playback and discard the matching channel's decoder state. Use the event's transcript only when it is present. See Ending an Oracle Radio WebSocket Audio Transmission. -
Process a later
TRANSCRIPT_FINALevent when the service provides one. Do not wait indefinitely or assume that every transmission produces this optional event. -
Process
CHANNEL_OPENas the notification that the channel is idle. Stop playback and discard the matching channel's decoder state, even if noTRANSMISSION_ENDevent arrived. See Releasing the Oracle Radio WebSocket Talk Floor.
Handle Invalid State and Disconnects
- Discard a binary message if it is shorter than the 2-byte length field, its channel-name length extends past the message, or it has no matching transmission state. Do not interpret it as unframed client-to-server audio.
- On a WebSocket disconnect, stop playback and discard all decoder state. Reconnect and subscribe to the required channels again before accepting more channel audio.