搜索插件、代码仓与 APP 分类

插件详情v1.1.12

flutter_audio_capture

通过麦克风捕获音频缓冲流,适用于 iOS/Android。

AndroidiOSLinux
近 30 天下载
1150
喜欢数
34
Pub 分数
130

安装插件

flutter pub add flutter_audio_capture

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

flutter_audio_capture 是一个 Flutter 插件,可在 Android、iOS 和 Linux 上实现设备麦克风的实时音频录制。它提供对原始音频缓冲区流的访问,适用于需要低级别音频处理的应用程序,例如语音分析、实时音频效果或自定义音频处理流程。该包与 Flutter 的事件驱动架构无缝集成,并支持可配置采样率和通道数的连续音频流。非常适合需要直接控制音频输入的音频中心应用程序开发者。

适合场景

  • 实时语音处理
  • 音频可视化
  • 语音控制的应用程序
  • 实时音频流
  • 自定义音频效果

主要特点

  • 原始音频缓冲区流访问
  • 跨平台支持(Android、iOS、Linux)
  • 可配置的采样率和通道
  • 低延迟音频捕获
  • 事件驱动流式 API

适合对象

  • 音频分析工具
  • 语音识别系统
  • 音乐制作应用
  • 互动音频体验
  • 实时通信应用

使用建议

  • 需要麦克风权限
  • 可能消耗大量电池电量
  • 持续捕获期间CPU使用率过高
  • 有限的文档
  • 需要平台特定的配置

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

flutter_audio_capture

Capture the audio stream buffer through microphone for iOS/Android. Required OS version is iOS 13+ or Android 23+

Getting Started

Add this line to your pubspec.yaml file:

dependencies:
  flutter_audio_capture: ^1.1.12

and execute

$ flutter pub get
Android

If you want to use this package on Android OS, you need to set RECORD_AUDIO permission to AndroindManifest.xml like below.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.ymd.flutter_audio_capture">
  ...
  // Add this line
  <uses-permission android:name="android.permission.RECORD_AUDIO"/>
</manifest>
iOS

If you want to use this package on iOS, you need to set NSMicrophoneUsageDescription to Info.plist like below.

<dict>
    <key>NSMicrophoneUsageDescription</key>
    <string>Need microphone access to capture audio</string>
...
Linux

On Linux, this package uses parec to record audio.

While things should just work on recent Ubuntu versions, make sure to have pulseaudio installed on the target device.

Example

You can see full example in example/lib/main.dart

import 'package:flutter_audio_capture/flutter_audio_capture.dart';
...

// Callback function if device capture new audio stream.
// argument is audio stream buffer captured through mictophone.
// Currentry, you can only get is as Float64List.
void listener(dynamic obj) {
  var buffer = Float64List.fromList(obj.cast<double>());
  print(buffer);
}

// Callback function if flutter_audio_capture failure to register
// audio capture stream subscription.
void onError(Object e) {
  print(e);
}

...

FlutterAudioCapture plugin = new FlutterAudioCapture();

// Initialize the plugin (required before start)
await plugin.init();

// Start to capture audio stream buffer
// sampleRate: sample rate you want
// bufferSize: buffer size you want (iOS only)
await plugin.start(listener, onError, sampleRate: 16000, bufferSize: 3000);

// Stop to capture audio stream buffer
await plugin.stop();

所属分类

源码仓库

使用此插件的项目