标题说明了一切。这样做是为了监测周围的噪音。一旦检测到某种模式,就应该将音频信号记录到文件中。困难在于,记录的文件应该在检测到模式之前几秒钟启动。因此,在内存中需要音频信号才能“返回”几秒钟。你知道如何实时地把原始音频输入到内存中吗?
发布于 2020-09-19 17:35:52
你可以使用颤振声音插件,使麦克风的原始音频信号进入内存实时。参考链接是:声音,演示示例在这里,body.dart
我有一个例子是
Widget _buildRecorder(Track track) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: RecorderPlaybackController(
child: Column(
children: [
Left("Recorder"),
SoundRecorderUI(track),
Left("Recording Playback"),
SoundPlayerUI.fromTrack(
track,
enabled: false,
showTitle: true,
audioFocus: true
? AudioFocus.requestFocusAndDuckOthers
: AudioFocus.requestFocusAndDuckOthers,
),
],
)));
}
}发布于 2020-09-17 17:53:33
流包可以帮助您将麦克风音频作为PCM格式的Stream<Uint8List>进行流。假设您拥有每秒16000个示例,您可以使用它创建一个产生n个音频块的流:
import 'dart:math'; // for min
import 'dart:typed_data'; // for Uint8List
import 'package:sound_stream/sound_stream.dart';
Stream<Uint8List> audioChunks([int seconds = 3]) async* {
final stream = RecorderStream();
await stream.initialize();
stream.start();
BytesBuilder buffer = BytesBuilder();
int filled = 0;
int max = seconds * 16000 * 2; // pcm 16bit = 2bytes / sample
await for (final chunk in stream.audioStream) {
int cl = min(max-filled, chunk.length);
buffer.add(chunk.sublist(0, cl));
filled += cl;
if (filled == max) {
yield buffer.toBytes();
filled = 0;
buffer.clear();
}
if (chunk.length > cl) {
buffer.add(chunk.sublist(cl));
filled += chunk.length - cl;
}
}
}https://stackoverflow.com/questions/63838554
复制相似问题