convertToWavBytes method

  1. @override
Future<Uint8List> convertToWavBytes(
  1. Uint8List inputData,
  2. String formatHint, {
  3. int? sampleRate,
  4. int? channels,
  5. int? bitDepth,
  6. bool? includeHeader,
})
override

Implementation

@override
Future<Uint8List> convertToWavBytes(
  Uint8List inputData,
  String formatHint, {
  int? sampleRate,
  int? channels,
  int? bitDepth,
  bool? includeHeader,
}) async {
  try {
    var buffer = await _decodeAudioData(inputData);
    if (sampleRate != null && sampleRate != buffer.sampleRate.toInt()) {
      buffer = await _resample(buffer, sampleRate);
    }
    return _encodeWav(
      buffer,
      targetChannels: channels,
      targetBitDepth: bitDepth,
      includeHeader: includeHeader ?? true,
    );
  } catch (e) {
    if (e is AudioConversionException) rethrow;
    throw AudioConversionException('WAV conversion failed: $e');
  }
}