我想做和申请谁来使用麦克风流,并直接在Flutter中播放它,谁可以帮助我,我在Internet上一无所获。谢谢!
最佳答案
您可以使用this库记录麦克风的音频。
用法
要使用此插件,请将audio_recorder
作为依赖项添加到pubspec.yaml
文件中。
Android
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
iOS
<key>NSMicrophoneUsageDescription</key>
<string>Record audio for playback</string>
示例
// Import package
import 'package:audio_recorder/audio_recorder.dart';
// Check permissions before starting
bool hasPermissions = await AudioRecorder.hasPermissions;
// Get the state of the recorder
bool isRecording = await AudioRecorder.isRecording;
// Start recording
await AudioRecorder.start(path: _controller.text, audioOutputFormat: AudioOutputFormat.AAC);
// Stop recording
Recording recording = await AudioRecorder.stop();
print("Path : ${recording.path}, Format : ${recording.audioOutputFormat}, Duration : ${recording.duration}, Extension : ${recording.extension},");
现在,您需要做的就是播放录制的声音文件。