sendAudio method

void sendAudio(
  1. List<int> audioData
)

Implementation

void sendAudio(List<int> audioData) {
  if (_state != WebSocketState.connected || _channel == null) {
    return;
  }

  if (audioData.isEmpty) {
    return;
  }

  try {
    final audioBytes = Uint8List.fromList(audioData);
    _channel!.sink.add(audioBytes);

    _audioPacketsSent++;
    _totalAudioBytesSent += audioBytes.length;

    if (_audioPacketsSent % 100 == 0) {
      print(
          'Sent $_audioPacketsSent audio packets (${_totalAudioBytesSent} bytes total)');
    }
  } catch (e) {
    print('Error sending audio data: $e');
    _updateState(WebSocketState.error);
  }
}