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

插件详情v0.7.2

mic_stream

一个用于从设备麦克风接收原始字节流的插件。音频以 `Stream` 形式返回。

AndroidiOSmacOS
近 30 天下载
725
喜欢数
99
Pub 分数
130

安装插件

flutter pub add mic_stream

插件介绍

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

mic_stream 包提供了一种简单的方法,通过 Dart Stream 访问设备麦克风的原始音频数据。它支持在 Android、iOS 和 macOS 上实时音频捕获,非常适合需要低级别音频处理的应用程序,例如语音识别、声音可视化或实时音频分析。该插件直接提供音频字节,使开发者可以按需处理编码、过滤或传输。通过 Flutter pub add 进行最少设置,即可无缝集成到现有项目中。

适合场景

  • 实时语音处理
  • 音频可视化
  • 语音控制的应用程序
  • 实时音频流
  • 声音分析

主要特点

  • 原始字节流输出
  • 跨平台支持(Android、iOS、macOS)
  • 实时音频捕获
  • 简单的流式 API
  • 轻量且依赖极少

适合对象

  • 开发音频分析工具的开发者
  • 需要低延迟麦克风输入的应用程序
  • 涉及自定义音频处理的项目
  • 原型设计语音功能
  • 移动音频应用

使用建议

  • 所有平台都需要麦克风权限
  • 仅限原始字节数据(无内置解码)
  • 可能需要额外的音频格式处理
  • 性能取决于设备功能
  • 某些平台可能限制背景音频

原始 README

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

mic_stream: 0.7.2

[Flutter Plugin] Provides a tool to get the microphone input as 8 or 16 bit PCM Stream. 32 bit and floating point PCM are experimental WIP.

About mic_stream:

As Flutter still lacks some functionality, this plugin aims to provide the possibility to easily get an audio stream from the microphone of mobile devices.

How to use:

The plugin mainly provides one method to provide a raw audio stream:

Stream<UInt8List> MicStream.microphone({options})

and a StreamTransformer to provide a Stream of individual samples (not lists of samples):

MicStream.toSampleStream

that you can use to transform your mic stream:

stream.transform(MicStream.toSampleStream)

Listening to this stream starts the audio recorder while cancelling the subscription stops the stream.

Available options are as follows:

audioSource: AudioSource      // The microphone you want to record from
sampleRate: int               // The amount of data points to record per second
channelConfig: ChannelConfig  // Mono or Stereo
audioFormat: AudioFormat      // 8 bit PCM or 16 bit PCM. Other formats are not yet supported

Some configuration options are platform dependent and can differ from the originally configured ones. You can check the real values using:

Future<int> sampleRate = await MicStream.sampleRate;
Future<int> bitDepth = await MicStream.bitDepth;
Future<int> bufferSize = await MicStream.bufferSize;
Permissions

Make sure you have microphone recording permissions enabled for your project. To do so, add this line to the AndroidManifest.xml:

<uses-permission android:name="android.permission.RECORD_AUDIO"/>

In the Info.plist:

<key>NSMicrophoneUsageDescription</key>
<string>Microphone access required</string>

You can disable the permission request dialogue by calling MicStream.shouldRequestPermission(false) This will lead to an error if no permission to record audio has been requested, though.

For MacOS:

Open macos/Runner.xcworkspace click Runner -> Signing & Capabilities -> Check "Audio Input"

Example:
// Init a new Stream
Stream<List<int>> stream = await MicStream.microphone(sampleRate: 44100);

// Start listening to the stream
StreamSubscription<List<int>> listener = stream.listen((samples) => print(samples));
// Transform the stream and print each sample individually
stream.transform(MicStream.toSampleStream).listen(print);
// Cancel the subscription
listener.cancel()

Note: This plugin is still under development, and some APIs might not be available yet. Feedback and Pull Requests are most welcome!

所属分类

依赖

依赖清单 1 项

源码仓库

使用此插件的项目

暂无相关数据。