Converting from 16-bit WAV to GSM using SOX - wav

I'm currently working on some telephony integration with Asterisk and a PHP web interface. I want to give the user an option to upload their own custom greeting in a wav file, and then once it's on the server convert the wav to a gsm file at 8000hz. Currently, i'm trying to use sox to accomplish this.
However, it seems like when I convert between anything other than an 8khz sav to gsm, the gsm file is severely distorted. It's almost like it slows down the file by a factor of 10 (a 3 second intro in wav format turns into a 30 second gsm file) I've tried several combinations of speed and resampling to no avail. Ideally, I would like to take any wav file that's uploaded and convert it, without putting too much responsibility on the user to encode it properly. I'm definitely not an audiophile, so if anybody could point me in the right direction it would be much appreciated.

This is the command that I use to convert regular 16-bit .wav files to 8-bit mono .gsm files (works fine):
sox input.wav -r 8000 -c1 output.gsm lowpass 4000 compand 0.02,0.05 -60,-60,-30,-10,-20,-8,-5,-8,-2,-8 -8 -7 0.05

I have seen cases with sox where I needed to break up changes and pipe them one after another rather then in one command.
What does your sox cmd look like?
Could you first convert the wav to 8khz, then transcode, piping the output from the one sox call to the other?

I use
sox foo.wav -r 8000 -c1 foo.gsm resample -ql

Just a little late, I current use:
sox somefile.wav -r 8000 -c1 output.gsm

Related

How to convert EBCDIC file to ASCII file using eighter UNIX or Informatica Power Center?

Can you please let me know the approach to convert ebcdic file to ascii file using unix or informatica?
I have searched in google but no clue and expert says it can be done through power exchange but not sure about it.
Below is the sample file for your reference and few files may come in fixed width and few may come in delimited format since we have multiple source applications which generates files.
Thanks in advance for your help and form past several days i have searched in google.
You can use command like:
iconv -f EBCDIC -t ASCII filename >output_filename
or with dd
dd conv=ascii if=filename of=output_filename

Change specific column if equal to something AWK

I have a list of search phrases. I'm trying to replace the third column to N/A if it is equal to "error". I used the following code to sucessfully do this on the second column. So, I'm not sure why it isn't working on the third column. Any thoughts?
data
protector new ipad,0,error
60 led lcd television,0,error
boost mobile new phone 2013,0,error
seagate st320014a,0,error
awk -F, '{$3=($3=="error"?"N/A":$3)}1' OFS=, nTotal.csv > n3Total.csv
Your awk command is correct, not efficient but correct. However, there could be other reasons as to why it may not be working.
There could be a trailing space after the error. Since you testing an exact match of the third column, it could fail.
You files are dos formatted. If you made the files on windows machine and are using it on unix/linux machines then you need to convert those line endings. Doing cat -vet will show ^M characters at the end. You can use dos2unix or similar utilities to convert it to unix format.
Try this awk
awk -F, '$3=="error" {$3="N/A"}1' OFS=, file
data
protector new ipad,0,N/A
60 led lcd television,0,N/A
boost mobile new phone 2013,0,N/A
seagate st320014a,0,N/A
Your solution gives:
data,,
protector new ipad,0,N/A
60 led lcd television,0,N/A
boost mobile new phone 2013,0,N/A
seagate st320014a,0,N/A
You see the extra ,, after data, since it creates two extra field in the way you are testing.

Unix Shell Script: sleep command not working

i have a scenario in which i need to download files through curl command and want my script to pause for some time before downloading the second one. I used sleep command like
sleep 3m
but it is not working.
any idea ???
thanks in advance.
Make sure your text editor is not putting a /r /n and only a /n for every new line. This is typical if you are writing the script on windows.
Use notepad++ (windows) and go to edit|EOL convention|UNIX then save it. If you are stuck with it on the computer, i have read from here [talk.maemo.org/showthread.php?t=67836] that you can use [tr -d "\r" < oldname.sh > newname.sh] to remove the problem. if you want to see if it has the problem use [od -c yourscript.sh] and /r will occur before any /n.
Other problems I have seen it cause is cd /dir/dir and you get [cd: 1: can't cd to /dir/dir] or copy scriptfile.sh newfilename the resulting file will be called newfilenameX where X is an invisible character (ensure you can delete it before trying it), if the file is on a network share, a windows machine can see the character. Ensure it is not the last line for a successful test.
Until i figured it out (i knew i had to ask google for something that may manifest in various ways) i thought that there was an issue with this linux version i was using (sleep not working in a script???).
Are you sure you are using sleep the right way? Based on your description, you should be invoking it as:
sleep 180
Is this the way you are doing it?
You might also want to consider wget command as it has an explicit --wait flag, so you might avoid having the loop in the first place.
while read -r urlname
do
curl ..........${urlname}....
sleep 180 #180 seconds is 3 minutes
done < file_with_several_url_to_be_fetched
?

How to create a 0 byte file in ksh.

This is probably obvious, but Google seems to have let me down. I need to create a zero byte file with arbitrary names on Unix (AIX, ksh). What is a good command that will do this. Something I can script obviously.
Just to be clear Im not doing anything stupid. This is a script to generate certain testing scenarios. (Checking proper behavior when handling 0-byte files.)
I figured it out.
touch $filename will do it.
Save your keystrokes and the unnecessary process, redirection will do:
$ > file
$ ls
file
Use dd:
dd if=/dev/null of=zero.out bs=0 count=0

cut exact time range from mp3/ogg

I have a heap of audio files on a CDN. Those are mp3's and ogg vorbises, in parallel. Those files are each worth about one hour of playback. I need to extract arbitrary parts from those files: I am given a filename (I can choose if I use the mp3 or ogg version) and two timestamps and I need the audio exactly between the given time positions. I don't want to download the whole file, so I think of using the Range http header.
I have complete control over the audio files, so I encoded them in fixed bitrate, to be able to estimate which bytes I should reach for. However, both formats use frames (or pages in vorbis's case), which must be decoded atomically.
The program I write is in Perl. I tried downloading a part of the file where I believe the given window to be contained, and then using Audio::Mad and Ogg::Vorbis::Decoder to parse the audio file fragments. However, both seem to fail to process the fragments, and only succeed when I serve an integral file.
So my question is: How can I get an exact span of an audio file without downloading the whole thing?
Answering "cut exact time range from mp3/ogg" - You can check out if the following fits Your needs:
ffmpeg -i InFile -vn -acodec copy -ss 00:00:00 -t 00:01:32 -threads 0 OutFile
where ss - start time, t - duration. It cuts indeed - no re-compressions.

Resources