如何在Flutter中将音频的StreamedResponse保存到文件中?
How to save StreamedResponse of audio to file in Flutter?
我正在尝试下载一个 Azure Blob,它是一个 WAV 文件。我使用 azblob 包下载文件,它 returns 一个流式响应。
这就是我到目前为止所做的。
// Download WAV file from Azure's Blob Storage Container
var file = await storage.getBlob(wavFileLink);
print(file);
这是调试控制台为 print(file)
显示的内容。
如何在Flutter中将StreamedResponse保存为WAV文件?提前谢谢你。
您可以使用以下代码将数据收集为字节数据:
var file = await storage.getBlob(wavFileLink);
Uint8List data = await file.stream.toBytes();
如果你真的想将数据保存为文件,你需要使用 path_provider
包:
dependencies:
path_provider: ^2.0.1
import 'package:path_provider/path_provider.dart';
//Obtain the directory you want. This is application documents.
var dir = await getApplicationDocumentsDirectory();
var sysFile = File('${dir.path}/file.wav');
sysFile.writeAsBytes(data);
我正在尝试下载一个 Azure Blob,它是一个 WAV 文件。我使用 azblob 包下载文件,它 returns 一个流式响应。
这就是我到目前为止所做的。
// Download WAV file from Azure's Blob Storage Container
var file = await storage.getBlob(wavFileLink);
print(file);
这是调试控制台为 print(file)
显示的内容。
如何在Flutter中将StreamedResponse保存为WAV文件?提前谢谢你。
您可以使用以下代码将数据收集为字节数据:
var file = await storage.getBlob(wavFileLink);
Uint8List data = await file.stream.toBytes();
如果你真的想将数据保存为文件,你需要使用 path_provider
包:
dependencies:
path_provider: ^2.0.1
import 'package:path_provider/path_provider.dart';
//Obtain the directory you want. This is application documents.
var dir = await getApplicationDocumentsDirectory();
var sysFile = File('${dir.path}/file.wav');
sysFile.writeAsBytes(data);