jeff1evesque / LeQue

Activate installed microphone, and analyze sound input
13 stars 2 forks source link

Reconfigure audio efficiently using ffmpeg #322

Closed jeff1evesque closed 10 years ago

jeff1evesque commented 10 years ago

It may be possible that the process of reconfiguring an audio file to 16 bit, 16 kHz, mono doubles the time it takes to translate an audio file to a text file compared to simply translating the audio to text, https://github.com/jeff1evesque/audio-analyzer/issues/236#issuecomment-48745620.

There is also a chance that the general process of bash automation doubles the translation time because of the general use of inotifywait. Regardless, which is the cause, we will proceed by changing the code within converter_wav_rate. That is, we will only reconfigure audio files into 16 bit, 16 kHz, mono if the audio file is in a different format. This will involve checking the format of the audio file, and implementing the corresponding logic. Otherwise, we will perform a simple cp command of the audio file from:

/var/www/audio-analyzer/audio/recording

into the directory:

/var/www/audio-analyzer/audio/recording_converted
jeff1evesque commented 10 years ago

d188c1e: Minor changes regarding spacing between lines of code.

jeff1evesque commented 10 years ago

a8c2c7c: Our initial assumption was correct. We made the changes involving only reconfiguring audio files that were not of the form 16 bit, 16 kHz, mono, otherwise we simply perform a cp command. The results indicate that the translation occurred in under a minute.

After Reboot: The following were executed immediately after sudo reboot:

$ cd /var/www/audio-analyzer/audio/recording
$ sudo rm * ../recording_converted/* ../recording_text/*
$ sudo cp ../../pocketsphinx/audio/sample.wav sample.wav
$ ls -l
-rw-r--r--  root  root  367922  2014-07-12  1:34  sample.wav
$ (cd ../recording_converted && ls -l)
-rw-r--r--  root  root  367922  2014-07-12  1:34  sample.wav
$ (cd ../recording_text && ls -l)
-rw-r--r--  root  root  180  2014-07-12  1:35  sample

Repeat: The following were executed immediately after above, without sudo reboot:

$ cd /var/www/audio-analyzer/audio/recording
$ sudo rm * ../recording_converted/* ../recording_text/*
$ sudo cp ../../pocketsphinx/audio/sample.wav sample.wav
$ ls -l
-rw-r--r--  root  root  367922  2014-07-12  1:37  sample.wav
$ (cd ../recording_converted && ls -l)
-rw-r--r--  root  root  367922  2014-07-12  1:37  sample.wav
$ (cd ../recording_text && ls -l)
-rw-r--r--  root  root  180  2014-07-12  1:38  sample
jeff1evesque commented 10 years ago

a8c2c7c: Our logic is reversed. Currently the logic reads, if the file is already properly configured, reconfigure it. This should be changed to, if the file is not properly configured, reconfigure it.

jeff1evesque commented 10 years ago

2464d97: Our correct logic produces similar time results as earlier.

After Reboot: The following were executed immediately after sudo reboot:

$ cd /var/www/audio-analyzer/audio/recording
$ sudo rm * ../recording_converted/* ../recording_text/*
$ sudo cp ../../pocketsphinx/audio/sample.wav sample.wav
$ ls -l
-rw-r--r--  root  root  367922  2014-07-12  9:19  sample.wav
$ (cd ../recording_converted && ls -l)
-rw-r--r--  root  root  367922  2014-07-12  9:19  sample.wav
$ (cd ../recording_text && ls -l)
-rw-r--r--  root  root  180  2014-07-12  9:20  sample

Repeat: The following were executed immediately after above, without sudo reboot:

$ cd /var/www/audio-analyzer/audio/recording
$ sudo rm * ../recording_converted/* ../recording_text/*
$ sudo cp ../../pocketsphinx/audio/sample.wav sample.wav
$ ls -l
-rw-r--r--  root  root  367922  2014-07-12  9:21  sample.wav
$ (cd ../recording_converted && ls -l)
-rw-r--r--  root  root  367922  2014-07-12  9:21  sample.wav
$ (cd ../recording_text && ls -l)
-rw-r--r--  root  root  180  2014-07-12  9:22  sample
jeff1evesque commented 10 years ago

We need to move filename="${file##*/}" outside the if-else logic, this way it can be used for both. Currently both blocks utilize the variable filename. However, only the else block defines it. There is a possibility this will resolve the issue of audio recordings from the browser not being translated.