For now, I have two txt files in my assets. One contains data in UInt8 format and another in UInt16 format. Both of them are of the same wav file. I need to create a wav file from the UInt16 file and UInt8 file is just for references.
Wav file from the Uint8 file
I am using the code below to create a wav file. It works. But this is not what I need.
var bytes = await rootBundle.loadString('assets/wav/audio_01_Uint8.txt');
List<int> bytesListString = await (bytes.split(', '));
for (String s in bytesListString) {
bytesListInt.add(int.parse(s));
}
Uint8List bytesUInt8 = Uint8List.fromList(bytesListInt);
await File(tempPath + '/audio_01_Uint8.wav')
.writeAsBytes(bytesUInt8);
Wav file from the Uint16 file
I am using the same process as for the UInt16 file but this doesn't create a playable wave file. It says that the file is empty.
var bytes = await rootBundle.loadString('assets/wav/audio_01_Uint16.txt');
List<int> bytesListString = await (bytes.split(', '));
for (String s in bytesListString) {
bytesListInt.add(int.parse(s));
}
Uint16List bytesUInt16 = Uint16List.fromList(bytesListInt);
await File(tempPath + '/audio_01_Uint16.wav')
.writeAsBytes(bytesUInt16);
Later, I will receive the data in UInt16 so I cannot use UInt8 to create a file. So, how can I create a wav file from the UInt16 data.