public class AudioConsumerUtils
extends java.lang.Object
Base class for consuming PCM data and pushing it to RTC channels.
In AI scenarios:
- When TTS returns data: Call AudioConsumerUtils.pushPcmData method to
directly
push the returned TTS data to AudioConsumerUtils
- In another "timer" trigger function, call AudioConsumerUtils.consume()
method
to push data to RTC
Recommendations:
- "Timer" can be implemented using various approaches .
Just need to call AudioConsumerUtils.consume() in the timer trigger function
- Timer trigger interval can be consistent with existing business timer
intervals or adjusted based on business needs,
recommended between 40-80ms
Usage Pattern:
1. Prerequisites:
- Application needs to implement its own timer with interval between
[10ms,80ms].
The timer trigger method is represented as app::TimeFunc.
- One user can only correspond to one AudioConsumerUtils object, ensuring one
producer corresponds to one consumer.
2. Usage Steps:
A. Create an AudioConsumerUtils object for each "PCM data producing" userid,
ensuring one producer corresponds to one consumer
B. When PCM data is generated (e.g., TTS return), call
AudioConsumer.AudioConsumerUtils(data)
C. When consumption is needed , call
AudioConsumerUtils.consume() method,
which will automatically complete data consumption by pushing to RTC channel
D. For interruption (e.g., stopping current AI dialogue): call
AudioConsumerUtils.clear() method,
which will automatically clear current buffer data
E. On exit, call release() method to free resources