Daniel Alexander
Daniel Alexander

Reputation: 160

List<Uint8List> to List<int> in dart

does anyone know how to convert a List<Uint8List> to a List<int>. I want to use it with the library Google Speech (Speech to Text using google api) and to use it I need to give the audio data with the format List<int>.

Upvotes: 3

Views: 7168

Answers (1)

jamesdlin
jamesdlin

Reputation: 89995

Uint8List derives from List<int>, so no conversion would be necessary if you start from just a Uint8List.

If, as you say, you have a List<Uint8List>, you would need to combine them into a single List. One way to do that:

final mergedList = [
  for (var sublist in listOfLists)
    ...sublist,
];

Depending on exactly what you're doing, there might be better, more specialized alternatives (e.g. collectBytes from package:async).

Upvotes: 5

Related Questions