Closed good-good-study closed 2 years ago
It is not possible to record mp3 with Flutter Sound on ios, android and web. Sorry!
toStream can only be used with codec == Codec.pcm16 What other audio formats are supported toStream?
Hello, the function I need to implement is to record the audio within 60s and convert it into text while recording. In addition to the pcm16 format, there are other formats supported ?
Thanks!
Sorry, record to stream only works with pcm16. You could try to encode the pcm16 data to mp3 with a mp3 encoder like 'lame'. This would be a major work. If you do something like that, I suggest that you publish your solution to pub.dev, because other developers will probably be interested by your work
Note : if you use 'startRecorderToFile()' and not 'startRecorderToStream()' you can:
This is very simple, but you will not get a stream on the fly. Again, if you want a real time mp3 stream you really must use a mp3 encoder like 'lame'. ('lame' is included with the FFmeg Kit plugin). This will be much more complicated than converting a Wave file to a MP3 file with just a very simple call to FFmpeg.
If you want to get mp3 files from 60 seconds batch records, I guess that the solution to call ffmpeg to convert WAVE files to MP3 files is certainly what you need and will be very simple to implement.
which version of flutter sound is more compatible
The last version 9.x is compatible with 'FFmpeg kit' plugin.
Future record() async { if (!isRecoderReady.value) return; Directory tempDir = await getTemporaryDirectory();
await recorder.startRecorder(
toFile: 'audio', codec: audio.Codec.defaultCodec);
}
Future stop() async { if (!isRecoderReady.value) return;
final path = await recorder.stopRecorder();
String fileName = path!.split('/').last;
FFmpegKit.execute('-i $path -c:a mp3 $path.mp3').then((session) async {
final returnCode = await session.getReturnCode();
if (ReturnCode.isSuccess(returnCode)) {
print('success');
} else {
print('error');
}
});
am always getting print error, how actually to use this package with lame encoder ?
await recorder.startRecorder( toFile: 'audio', codec: audio.Codec.defaultCodec);
You can try something like: ''' String path = '$tempdir/audio' ; startRecorder(toFile: '$path.wav', codec: Codec. pcmWav) ; ... FFmpegKit.execute('-i $path.wav $path.mp3').then(( ... '''
i tried startRecoding it records correctly, but path returned on stropRecorder is empty or says no such file directory
final path = await recorder.stopRecorder();
this method worked for me , its better to use aac format than mp3, it supports almost all kinds browsers
.....
Directory tempDir = await getApplicationDocumentsDirectory();
String path = tempDir.path + '/audio.aac';
print("directory path: $path");
//audioFile = await File('${tempDir.path}/audio.mp3');
await recorder.startRecorder(toFile: path, codec: audio.Codec.aacMP4);
}
await recorder.startRecorder( toFile: 'audio', codec: audio.Codec.defaultCodec);
You can try something like: ''' String path = '$tempdir/audio' ; startRecorder(toFile: '$path.wav', codec: Codec. pcmWav) ; ... FFmpegKit.execute('-i $path.wav $path.mp3').then(( ... '''
it‘s not work,
var ffmpegSession = await FFmpegKit.execute('-i $sourcePath $convertResultPath.mp3');
Automatic encoder selection failed for output stream #0:0. Default encoder for format mp3 (codec mp3) is probably disabled. Please choose an encoder manually. E/log FlutterLog convertAudio (27327): Error selecting an encoder for stream 0:0
How to record .mp3 file ?