首页 > 解决方案 > 从 Flutter 录制音频数据(16000Hz PCM 数据),捕获音频并将其发送到后端(Node.js)

问题描述

我正在尝试通过pub.dev中的 mic_stream 包录制音频(因为我想要 16000Hz PCM 数据),并尝试捕获数据并将其发送到 Nodejs 服务器。我没有对提供的链接中的 mic_stream 示例进行任何更改,但我想将 16000Hz PCM 格式的音频数据发送到 Nodejs 服务器。我尝试使用 http.MultipartFile ,如下所示:

var url = Uri.parse("http://localhost:3000/upload");
var request = new http.MultipartRequest("POST", url);
Future<int> length = stream.length;
var stream_length = http.ByteStream(stream);
request.files.add( await http.MultipartFile('music',stream,length,{
"filename1234.pcm"), new MediaType('audio', 'x-wav')});   
//This gives me error because length is not of int type

request.send().then((response) {
  print("test");
  if (response.statusCode == 200) print("Uploaded! ${response}");
  else   print("Failure");
});

我想知道这是否可行,或者是否有任何其他包可用于记录数据并以 PCM 格式 16000Hz 发送到 Nodejs。非常感谢任何帮助。

标签: node.jsflutterpostaudio-recording

解决方案


推荐阅读