Future<String> _combineRecordedFiles() async {
String savePath = '';
String savePathPcm = '';
String saveDirPath = await Utils.getSaveDirPath(Cons.BLOCK_TYPE_VOICE);
if (GetPlatform.isWindows) {
savePath = "$saveDirPath\\${randomId()}.wav";
} else if (GetPlatform.isMacOS) {
savePath = "$saveDirPath/${randomId()}.wav";
}
try {
await File(savePath).create(recursive: true);
// 初始化一个空的Uint8List来存储所有文件的字节数据
Uint8List combinedBytes = Uint8List(0);
LogUtils.e('savePath =====> : $savePath');
// var outputFile = File(savePath).openWrite();
await Future.forEach(_recordedFiles, (String filePath) async {
File file = File(filePath);
if (file.existsSync()) {
// await outputFile.addStream(file.openRead());
await convertWavToPcm(filePath, savePathPcm);
List<int> bytes = await File(savePathPcm).readAsBytes();
combinedBytes = Uint8List.fromList([...combinedBytes, ...bytes]);
}
});
// Close the output file
// await outputFile.close();
// 将累积的所有字节写入到输出文件
// await outputFile.writeFrom(bytes: combinedBytes);
await File(savePath).writeAsBytes(combinedBytes);
// await outputFile.flush(); // 确保数据被立即写入磁盘
// await outputFile.close();
LogUtils.i('Combined audio saved at: $savePath');
} catch (e) {
LogUtils.e('Error concatenating files: $e');
}
return savePath;
}
flutter 文件合成
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- [图片上传失败...(image-2e0a59-1600661451880)] 讯飞 TTS语音合成 Flutte...
- 当我们需要把一些pdf文件合并成一个pdf文件的时候,但是pdf文件又不能直接操作,该怎么办,下面我们就可以用一些...
- 我的需求是可以录制多个文件,最后生成的文件格式为mp3形式,查了下各种资料,因为swift无法直接将音频录制为mp...
- 在最近的一个项目中,需要制作系统的操作视频并配音,试了一下科大讯飞的在线语音合成感觉不错,于是想将解说词写到脚本文...