is it possible to have the time (in minutes and seconds) while converting audio to text with pocketsphinx - audio

I am using pocketsphinx to convert audio to text in ubuntu, the result contains text but to have also the time (in minutes and seconds) while converting audio to text with pocketsphinx, in addition to the generated text fromthe audio I want the time (in minutes and seconds) during which a word or phrase is pronounced. I am using this command :
pocketsphinx_continuous -infile file.wav 2> pocketsphinx.log > result.txt

pocketsphinx_continuous -time yes -infile file.wav 2> pocketsphinx.log > result.txt

Related

Chopping audio files with ffmpeg get None duration python 3

I have a long list of audio files, and some of them are longer than an hour. I am using Python 3.6, Jupyter notebook by connecting to a remote machine and using TinyTag library to get a duration of audio. Ffmpeg version is 2.8.14-0ubuntu0.16.04.1.
My code below goes over the files and if a file is longer than an hour, it splits the file into one-hour long pieces, and a leftover piece less than an hour, and copies the pieces as fname_0, fname_1,fname_2, etc. Before chopped, each file is .m4a but during chopping, they are converted to a .wav file. However, after this chopping process, when reading the duration of pieces, I realized that all the pieces have 'None' duration. Something must be wrong in the command line but I can`t see what that is. Thanks in advance.
# fpaths is the list of filepaths
for i in range(0,len(fpaths)):
fpath=fpaths[i]
fname=os.path.basename(fpath)
fname0=os.path.splitext(fname)[0] #name without extension
tag = TinyTag.get(fname)
if tag.duration > 3600:
cmd2 = "ffmpeg -i %s -f segment -segment_time 3600 -c copy %s" %(fpath, fname0) + "_%d.wav"
os.system(cmd2)
os.remove(fpath)
When I change to the extension from .wav to .m4a in the cmd2 command line, it works. Writing here just in case if someone has the same problem.

ffmpeg being inprecise when trimming mp3 files

I want to use ffmpeg to trim some mp3s without re-encoding. The command I used was
ffmpeg -i "inputfile.mp3" -t 00:00:12.414 -c copy out.mp3
However, out.mp3 has a length of 12.460s, and when I load the file in Audacity I can see that it was cut at the wrong spot, and not at 12.414s.
Why is this? I googled a bit and tried some other commands like ffmpeg -i "inputfile.mp3" -ss 0 -to 00:00:12.414 -c copy out.mp3 (which interestingly results in a different length of 12.434s) but could never get the milliseconds to be cut right.
PS. I wasn't sure whether SO was the right place to ask since it isn't technically programming related, however most of the stuff I found on ffmpeg for trimming audio files were stackoverflow questions, e. g. ffmpeg trimming videos with millisecond precision
You can't trim MP3 (nor most lossy codec output) with that level of precision. An MP3 frame or so of padding is added during encoding. (See also: https://wiki.hydrogenaud.io/index.php?title=Gapless, and all the hacks required to make this work.)
If you need precision timing, use something uncompressed like PCM in WAV, or a lossless compression like FLAC.
On Linux you can use mp3splt:
mp3splt -f mp3file.mp3 from to -o output file format
Example:
mp3splt -f "/home/audio folder/test.mp3" 0.11.89 3.25.48 -o #f_trimmed
this will create a "/home/audio folder/test_trimmed.mp3"
For more info to the parameters, check the mp3splt man page here
On Windows you can use mp3DirectCut
mp3DirectCut has a GUI, but it also have command line support

Text Based User Interface to stdout

I'm working on a headless device to play music, and I'm using Sox's play command to play the file.
I'm after a way to pipe the output formatted like this:
$play File.wav
File.wav:
File Size: 1.25M
Bit Rate: 64.0k
Encoding: Unsigned PCM Channels:
1 # 8-bit
Samplerate: 8000Hz
Replaygain: off
Duration: 00:02:36.87
In:42.4% 00:01:06.56
[00:01:30.31] Out:532k [ -===|===- ] Clip:0
To be readable in a text file so it can be parsed by PHP and ouputted to the user.
I've tried the standard things like:
$play File.wav >> output.txt
which results in a file being created but an empty one, I don't need it to be realtime, just every few seconds, or even once per run just to check it's going ok.
Any ideas?
Try the following (it would appear that sox outputs on STDERR):
play File.wav >> output.txt 2>&1
Whether it's going to be easy to parse is a different story ... :)
Namely the
[00:01:30.31] Out:532k [ -===|===- ] Clip:0
bit gets broken up over individual lines with your redirect.

Command line program for playing sections of audio specified in milliseconds

Would someone kindly recommend a command line utility that can play any section of an audio file specified in milliseconds e.g.
player -start-time=0.1234 end-time=5.6789 audio.wav
None of the audio players that I've come across seem to have this functionality. vlc supports start and end times but in seconds only, while Audacity does not appear to have much in the way of command line options.
sox
You can use sox play with the trim effect:
play audio.wav trim START =END
Which in your case would become:
play audio.wav trim 0.1234 =5.6789
Note that the end can also be specified as a length:
play audio.wav trim 0.1234 2
Which starts playing at 0.1234 and plays 2 seconds of the file.
Also note that the offsets can be specified as number of samples by appending an s to the number.
mplayer
mplayer also supports this:
mplayer -ss START -endpos END audio.wav
ffplay from ffmpeg
ffplay uses similar input parameters but doesn't support absolute end times, so some minor arithmetic is needed:
ffplay -ss START -t $(( END - START )) audio.wav

ffmpeg: How can I add video-1 at the beginning of video-2

I want to add video-1 at the beginning of video-2 with command line in linux, is it possible?
Run ffmpeg -i input.flv output.mpg to convert video format to mpg,
then run cat *.mpg > all.mpg

Resources