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
9 stars 10 forks source link

More Help Needed... Opus Stream Encoder #2

Closed jeffmikels closed 3 years ago

jeffmikels commented 3 years ago

I'm using the audio_recorder_mc package which gives me audio data from the microphone as 32 bit floats in packets of type List<dynamic>.

I am creating the opusEncoder like this:

Future<Stream<dynamic>> startRecorder() async {
    opusEncoder = StreamOpusEncoder<double>.float(
      frameTime: FrameTime.ms40,
      sampleRate: MumbleConnection.sampleRate,
      channels: MumbleConnection.audioChannels,
      application: Application.voip,
      fillUpLastFrame: true,
    );

    var stream = await audioRecorder.startRecord;
    return stream
        .map<Float32List>((event) => Float32List.fromList(event.whereType<double>().toList()))
        .cast<List<double>>()
        .transform<Uint8List>(opusEncoder);
}

But I keep getting an Exception when the encoder gets data to the stream.

Can you help me clean up this code and tell me what else I'm doing wrong? Do I need to send frames one at a time to the stream encoder or can I just send the raw floats like I'm doing?

EP-u-NW commented 3 years ago

Can you again create an exampel repo? Adding the floats raw should be fine. What is the exception you get? To test if the error is with encoding or recording you could try to convert the floats to s16le by multiplying each float with 2^31-1 and putting the result in an Int16List (If I remember correctly, encoding with ints already worked?). Btw on which platform are you testing?

jeffmikels commented 3 years ago

Thanks for the advice... I determined the error is that I wasn't sending an appropriately sized packet to the encoder. As you have documented, opus needs a specific size frame and I thought the streaming encoder would handle that for me. I was just sending bytes as I got them thinking the streaming encoder would buffer them until it had a full frame.

EP-u-NW commented 3 years ago

If I remember right, the stream encoder should do buffring... Maybe I need to do some investigations 😅