EPNW / opus_flutter

Repository for the federal organized opus_flutter plugin, which is needed to easily obtain a DynamicLibrary of opus for the use in opus_dart on flutter platforms.
https://pub.dev/packages/opus_flutter
10 stars 13 forks source link

Need help understanding how to use decoder #15

Open agbossi opened 1 year ago

agbossi commented 1 year ago

I'm trying to decode opus audio data by trying to copy that part of the example in the documentation. However I can't even get it to compile. I'm assuming I'm doing something wrong, but since it's practically a simplified copy, don't know what.

import 'package:opus_flutter/opus_flutter.dart' as opus_flutter;
import 'package:opus_dart/opus_dart.dart';

 static Future<Uint8List> decodeOpus(
    Stream<Uint8List> input, int sampleRate) async {
    List<Uint8List> output = [];
    await input.transform(StreamOpusDecoder.bytes(
          floatOutput: false,
          sampleRate: sampleRate,
          channels: 1,
          copyOutput: true,
          forwardErrorCorrection: false))
      .cast<Uint8List>()
      .forEach(output.add);
    return output[0];
  }

the error is

The argument type 'StreamOpusDecoder' can't be assigned to the parameter type 'StreamTransformer<Uint8List, dynamic>'.
agbossi commented 1 year ago

I realized I am not initializing the library. Also found a simpler class. What I'm trying to do is

    import 'package:opus_dart/opus_dart.dart';
    import 'package:opus_flutter/opus_flutter.dart' as opus_flutter;

    var lib = await opus_flutter.load();
    initOpus(lib);
    _decoder = SimpleOpusDecoder(sampleRate: sampleRate, channels: 1);

  static Future<Int16List> decodeOpus(input, int sampleRate) async {
    Int16List output = _decoder.decode(input: input);
    return output;
  }

the decoder is called after initialization. Now the error is in runtime

OpusException -1: invalid argument
When the exception was thrown, this was the stack:
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 266:49    throw_
packages/opus_dart/src/opus_dart_decoder.dart 73:9                              new

Any idea what this error means?