The RTC SDK provides the function to obtain audio data. You can process the obtained audio data based on your actual needs. By reading this article, you can learn how to obtain audio data.
Scenarios
You can convert audio data from a local publisher or subscriber to text by using the Alibaba Cloud speech recognition service. The implementation process is as follows:
- Alibaba Cloud RTC sends audio data to the audio recognition SDK.
- The audio recognition SDK sends audio data to the audio recognition service for real-time speech processing and returns recognition results.
- The audio recognition SDK provides recognition results for users.
Architecture

Call sequence diagram

Interface and usage
By inheriting the AliRtcEventListener callback class, the onAudioSampleCallback callback receives audio media data and uses the corresponding data source according to the business scenario.
onAudioSampleCallback: the callback of the subscribed audio data.
| Parameter | Type | Description |
| type | AliRtcAudioSource | The type of the audio data source. |
| audioSample | AliRtcAudioDataSample * | The audio data. |
Speech data processing
RTC obtains audio data as follows:
- After the application creates an AliRtcEngine engine instance, it registers an audio data callback.
AliRtcEngine *mpEngine = AliRtcEngine::sharedInstance(listener, extras); // Start local audio data collection and output. For more information about other types of type output, see the enumeration AliRtcAudioSource. mpEngine->setSubscribeAudioNumChannel(AliRtcMonoAudio); mpEngine->setSubscribeAudioSampleRate(AliRtcAudioSampleRate_32000); mpEngine->subscribeAudioData(AliRtcAudiosourceRawData); // Start audio streaming and subscribe to videos from other users. .....Note- The callback output is only available when the microphone is turned on to start pushing audio streams for local audio data collection. The callback output is also available when the remote video data is subscribed to the audio streams of other users.
- The AliRtcAudioSourceVolume type in the audio type enumeration AliRtcAudioSource is the registered user volume value callback. When you register a subscription to this type, the user volume will be returned through the onAudioVolumeCallback callback, which is different from the audio data output callback.
- If you need to stop receiving bare video data, you can call the unsubscribeAudioData to disable audio data output. Note The stop type must correspond to the audio data type registered in Step 1.
// Stop local audio data collection and output. pEngine->unsubscribeAudioData(AliRtcAudiosourceRawData);
该文章对您有帮助吗?