ffmpeg audio conversion in flutter - flutter

I would like to get data from audio file based on microphone input (both Android and iOS), currently I'm using audioplayers and recordMp3 to record the microphone input. This results in a mp3 file with a local file path. In order to use the audio data, I want an uncompressed format like WAV. Would ffmpeg help with this conversion ? I want to eventually use this data for visualization.

MP3 to WAV
ffmpeg -i input.mp3 output.wav
Note that any encoding artifacts in the MP3 will be included in the WAV.
Piping from ffmpeg to your visualizer
I'm assuming you need WAV/PCM because your visualizer only accepts that format and does not accept MP3. You can create a WAV file as shown in the example above, but if your visualizer accepts a pipe as input you can avoid creating a temporary file:
ffmpeg -i input.mp3 -f wav - | yourvisualizer …
Using ffmpeg for visualization
See examples at How do I turn audio into video (that is, show the waveforms in a video)?

Related

Flutter FFmpeg moov atom not found whilst running ffmpeg command during recording

Hi am currently trying to retrieve 3 second clips of an audio file whilst it is recording in flutter. I am using the recording module flutter sound and flutter ffmpeg.
I record the audio file with default codec (.aac). The file is saved to the cache getTemporaryDirectory()
I then copy the file using this flutter ffmpeg code
List<String> arguments = ["-ss", start.toString(), "-i", inPath, "-to", end.toString(), "-c", "copy", outPath];
await flutterFFmpeg.executeWithArguments(arguments);
Start: start time (e.g. 0) and End: end time (e.g. 3)
It then returns this error
FFmpeg exited with rc: 1 [mov,mp4,m4a,3gp,3g2,mj2 # 0x748964ea00] moov
atom not found
Helpful information:
A moov atom is data about the file (e.g timescale,duration)
I know the inPath exists because I check that before executing ffmpeg command
The outPath is also format .aac
This ffmpeg function is being ran whilst the recording is still occurring
Example inPath uri looks like this /data/user/0/com.my.app/cache/output.aac
I have no problems when running on iOS, only on android
I would be grateful for help, I have spent many days trying to fix this problem. If you need anymore info please leave a comment. Thanks
Default Codec is not guaranteed to be AAC/ADTS.
It will depend of the Android version of your device.
You can do several things to understand better :
ffprobe on your file to see what has been recorded by Flutter Sound.
Use a specific Codec instead of default : aac/adts is a good choice because it can be streamed (you want to process the audio data during the recording and not after closing the file)
Verify that your file contains something and that the data are not still in internal buffers
Record to a dart PCM stream instead of a file. Working with a file and use FFmpeg to seek into it is complicated and perhaps does not fill your needs.

Google cloud text to speech silence at the beginning and at the end of generated mp3

I need to quickly play several generated audio file from google cloud text to speech service.
Here is what i get:
https://yadi.sk/i/jbkGpd23bprmyw
As you see it has about 0.15-0.3 s silence at the beginning and at the end of mp3 data.
Is there a way to tell API not to include these silent parts?
You can use ffmpeg to extract the portion of the audio clip you wish to keep.
For example, if you want the 0.5 seconds in the middle of a 0.8 second clip with 0.15s of silence at the beginning and end you set -t 00:00:00.500 (length of audio to keep) and use -ss 00:00:00.150 parameter at the beginning to set where to start.
Full command will look like this:
ffmpeg -ss 00:00:00.150 -i ttsclip.mp3 -t 00:00:00.500 -acodec copy ttsclip-cut.mp3

VLC: How to stream a wave via HTTP

I want to stream from my rapsberry the microphone via HTTP with VLC.
This command works fine:
vlc -vvv alsa://hw:1,0 --sout '#transcode{vcodec=none,acodec=mpga,ab=128,channels=2,samplerate=44100}:standard{access=http,mux=mp3,dst=192.168.178.30:8080}'
But when changing the code to s16l and mux to wav I can't hear anything in the VLC.
This is the command I've tried:
vlc -vvv alsa://hw:1,0 --sout '#transcode{vcodec=none,acodec=s16l,channels=1,samplerate=16000,scodec=none}:standard{access=http,mux=wav,dst=192.168.178.30:8080}'
Bu the same codec using RTP works:
vlc -vvv alsa://hw:1,0 --sout '#transcode{vcodec=none,acodec=s16l,channels=1,samplerate=16000,scodec=none}:rtp{dst=192.168.178.30,port=1234,sdp=rtsp://192.168.178.30:8080/test.sdp}'
Some logs: https://gist.github.com/timaschew/9e7e027cd1b371b01b0f186f23b47068
Not all codecs can be muxed, check VLC documentation.
Currently PCM(wave) can be muxed only in RTP.
mux is the encapsulation method required for streaming. wav in VLC is a container intended for storing.
Wave is a file container type, it can hold different types of codec data (compressed /uncompressed).
[Wiki]
Audio in WAV files can be encoded in a variety of audio coding formats, such as GSM or MP3, to reduce the file size.
This is a reference to compare the monophonic (not stereophonic) audio quality and compression bitrates of audio coding formats available for WAV files including PCM, ADPCM, Microsoft GSM 06.10, CELP, SBC, Truespeech and MPEG Layer-3.
For HTTP streaming using VLC
Select the Codec you need to stream like mp3 codec.
Note : Muxing is not applicable here

Problem of converting caf files using libsnd

I m building a voice recording application in iPhone. The recorded file is transfer to linux server and it need to be converted to wav file.
However, when I try to convert caf file using libsnd, it gives an error.
Error : Not able to open input file testfile.caf
For testing I converted some wave file to caf using libsnd and vice versa.
So I think that there is a problem of my recorded file in iphone.
Anyone has got such an experience ?
I hope can someone help me.
Thanks.
If you use AVAudioRecorder, AudioFile, or any of the other Core Audio APIs, you should be able to record directly to a WAV file, and skip the entire conversion process altogether.
But if you need to convert audio files, first check if the CAF file is a valid file. Does it play? Is the header correct? What is the data format? Is it compressed? Does libsnd support the data format?
(The data format is separate from the file format, which is just a container for various bits of data as well as the sample data. The data format could be PCM, or it could be compressed in any format such as MP3, AAC, uLaw, etc.)

iPhone - stuff "silence" in the beginning of an audio file

I am using AVAudioRecorder in my app in order to create a .wav file based on user voice input. I want to be able to stuff" silence in the beginning of an audio file for some time before the actual recording is done.
How can I do this using AVAudioRecorder? Can I mention a time for which I want the "silence" to be recorded?
Thanks.
I haven't worked with the AVAudioRecorder in particular. But silence in PCM audio is just zeros as sample values. You could set the encoding of the AVAudioRecorder to PCM, store the file and then edit the file by prepending the desired number of zeros in the beginning. E.g. at 44100 Hz, 8-bit encoding, you'd add 44100 zero-bytes to the beginning of the file for each second of silence you would like to have. Hope this helps as an idea.
Note: Keep the file header of the PCM file intact and edit the "data chunk".
I'm sure there's probably a better way to do it, but how about simply pre-recording the silent stream you want and then concatenating that file with a file of the user generated content before saving out the final version?