chipweinberger / flutter_pcm_sound

A flutter plugin for playing raw PCM audio data (16-bit integer)
Other
16 stars 7 forks source link

how to play Uint8List #20

Closed shingohu closed 2 weeks ago

shingohu commented 2 weeks ago

How to convert Uint8List to PcmArrayIt16 for playback? I used PcmArrayIt16.fromList (audio) and it couldn't play `properly. If I modify the feed method to the following way, it can play normally

  static Future<void> feed1(Uint8List buffer) async {
    return await _invokeMethod('feed', {'buffer': buffer});
  }
chipweinberger commented 2 weeks ago

PcmArrayInt16.fromList(List<int> list) expects integer range 0-65536

you probably are passing 0-255 range integers.

you can try PcmArrayInt16({required this.bytes}); instead.

shingohu commented 2 weeks ago

PcmArrayInt16

Sorry, I'm not quite sure how to convert Uint8list to ByteData, and I can't play it properly using the following methods FlutterPcmSound.feed(PcmArrayInt16(bytes: ByteData.view(data.buffer)));

chipweinberger commented 2 weeks ago
Uint8List uint8List = Uint8List.fromList([1, 2, 3, 4]); // Example data
ByteData byteData = uint8List.buffer.asByteData();
shingohu commented 2 weeks ago
Uint8List uint8List = Uint8List.fromList([1, 2, 3, 4]); // Example data
ByteData byteData = uint8List.buffer.asByteData();

I have tried this method before, but it did not work

Can you provide a feed method that directly passes Uint8List

chipweinberger commented 2 weeks ago

no. because uint8list does not specify which endianness it is.

does the example work? start with the example, and debug why it works and yours does not.

print the bytes.

shingohu commented 2 weeks ago

不,因为 uint8list 没有指定它是哪种字节顺序。

这个例子能工作吗?从例子开始,调试为什么它能工作而你的不能。

打印字节。 I haven't used an example . our app recorded 8k 16 bit single channel data using record and played it back through this library.