Wednesday, July 25, 2012

15 Awesome Examples to Manipulate Audio Files Using Sound eXchange (SoX)


How to use sox command for audio file manupulation:

1. Combine Multiple Audio Files to Single File

With the -m flag, sox adds two input files together to produce its output. The example below adds first_part.wav and second_part.wav leaving the result in whole_part.wav. You can also use soxmix command for this purpose.

$ sox -m first_part.wav second_part.wav whole_part.wav    (or)    $ soxmix first_part.wav second_part.wav whole_part.wav

2. Extract Part of the Audio File

Trim can trim off unwanted audio from the audio file.

Syntax : sox old.wav new.wav trim [SECOND TO START] [SECONDS DURATION].
  • SECOND TO START – Starting point in the voice file.
  • SECONDS DURATION – Duration of voice file to remove.

The command below will extract first 10 seconds from input.wav and stored it in output.wav

$ sox input.wav output.wav trim 0 10

3. Increase and Decrease Volume Using Option -v

Option -v is used to change (increase or decrease ) the volume.

Increase Volume

$ sox -v 2.0 foo.wav bar.wav

Decrease Volume

If we need to lower the volume on some files, we can lower them by using negative numbers. Lower Negative number will get more soft . In the following example, the 1st command (-0.5) will be louder than the 2nd command (-0.1)

$ sox -v -0.5 srcfile.wav test05.wav    $ sox -v -0.1 srcfile.wav test01.wav

4. Get Audio File Information

The stat option can provide lot of statistical information about a given audio file. The -e flag tells sox not to generate any output other than the statistical information.

$ sox foo.wav -e stat  Samples read: 3528000  Length (seconds): 40.000000  Scaled by: 2147483647.0  Maximum amplitude: 0.999969  Minimum amplitude: -1.000000  Midline amplitude: -0.000015  Mean norm: 0.217511  Mean amplitude: 0.003408  RMS amplitude: 0.283895  Maximum delta: 1.478455  Minimum delta: 0.000000  Mean delta: 0.115616  RMS delta: 0.161088  Rough frequency: 3982  Volume adjustment: 1.000

5. Play an Audio Song

Sox provides the option for playing and recording sound files. This example explains how to play an audio file on Unix, Linux. Playing a sound file is accomplished by copying the file to the device special file /dev/dsp. The following command plays the file music.wav: Option -t specifies the type of the file /dev/dsp.

$ sox music.wav -t ossdsp /dev/dsp

You can also use play command to play the audio file as shown below.

Syntax :play options Filename audio_effects    $ play -r 8000 -w music.wav

6. Play an Audio Song Backwards

Use the 'reverse' effect to reverse the sound in a sound file. This will reverse the file and store the result in output.wav

$ sox input.wav output.wav reverse

You can also use play command to hear the song in reverse without modifying the source file as shown below.

$ play test.wav reverse

7. Record a Voice File

'play' and 'rec' commands are companion commands for sox . /dev/dsp is the digital sampling and digital recording device. Reading the device activates the A/D converter for sound recording and analysis. /dev/dsp file works for both playing and recording sound samples.

$ sox -t ossdsp /dev/dsp test.wav

You can also use rec command for recording voice. If SoX is invoked as 'rec' the default sound device is used as an input source.

$ rec -r 8000 -c 1 record_voice.wav

8. Changing the Sampling Rate of a Sound File

To change the sampling rate of a sound file, use option -r followed by the sample rate to use, in Hertz. Use the following example, to change the sampling rate of file 'old.wav' to 16000 Hz, and write the output to 'new.wav'

$ sox old.wav -r 16000 new.wav

9. Changing the Sampling Size of a Sound File

If we increase the sampling size , we will get better quality. Sample Size for audio is most often expressed as 8 bits or 16 bits. 8bit audio is more often used for voice recording.

  • -b Sample data size in bytes
  • -w Sample data size in words
  • -l Sample data size in long words
  • -d Sample data size in double long words

The following example will convert 8-bit audio file to 16-bit audio file.

$ sox -b input.wav -w output.wav

10. Changing the Number of Channels

The following example converts mono audio files to stereo.  Use Option -c to specify the number of channels .

$ sox mono.wav -c 2 stereo.wav

There are methods to convert stereo sound files to mono sound.  i.e to get a single channel from stereo file.

Selecting a Particular Channel

This is done by using the avg effect with an option indicating what channel to use. The options are -l for left, -r for right, -f for front, and -b for back.  Following example will extract the left channel

$ sox stereo.wav -c 1 mono.wav avg -l

Average the Channels

$ sox stereo.wav -c 1 mono.wav avg

11. Audio Converter – Music File Format Conversion

Sox is useful to convert one audio format to another. i.e from one encoding (ALAW, MP3) to another. Sox can recognize the input and desired output formats by parsing the file name extensions . It will take infile.ulaw and creates a GSM encoded file called outfile.gsm. You can also use sox to convert wav to mp3.

$ sox infile.ulaw outfile.gsm

If the file doesn't have an extension in its name , using '-t' option we can express our intention . Option -t  is used to specify the encoding type .

$ sox -t ulaw infile -t gsm outfile

12. Generate Different Types of Sounds

Using synth effect we can generate a number of standard wave forms and types of noise. Though this effect is used to generate audio, an input file must still be given, '-n' option is used to specify the input file as null file .

$ sox -n synth len type freq
  • len – length of audio to synthesize. Format for specifying lengths in time is hh:mm:ss.frac
  • type is one of sine, square, triangle, sawtooth, trapezium, exp, [white]noise, pinknoise, brown-
    noise. Default is sine
  • freq – frequencies at the beginning/end of synthesis in Hz

The following example produces a 3 second 8000 kHz, audio file containing a sine-wave swept from 300 to 3300 Hz

$ sox -r 8000 -n output.au synth 3 sine 300-3300

13. Speed up the Sound in an Audio File

To speed up or slow down the sound of a file, use speed to modify the pitch and the duration of the file. This raises the speed and reduces the time. The default factor is 1.0 which makes no change to the audio. 2.0 doubles speed, thus time length is cut by a half and pitch is one interval higher.

Syntax: sox input.wav output.wav speed factor    $ sox input.wav output.wav speed 2.0

14. Multiple Changes to Audio File in Single Command

By default, SoX attempts to write audio data using the same data type, sample rate and channel count as per the input data. If the user wants the output file to be of a different format then user has to specify format options. If an output file format doesn't support the same data type, sample rate, or channel count as the given input file format, then SoX will automatically select the closest values which it supports.

Converting a wav to raw. Following example convert sampling rate , sampling size , channel in single command line .

$ sox -r 8000 -w -c 1 -t wav source -r 16000 -b -c 2 -t raw destination

15. Convert Raw Audio File to MP3 Music File

There is no way to directly convert raw to mp3 file because mp3 will require compression information from raw file . First we need to convert raw to wav. And then convert wav to mp3.  In the exampe below, option -h indicates high quality.

Convert Raw Format to Wav Format:

$ sox -w -c 2 -r 8000 audio1.raw audio1.wav

Conver Wav Format to MP3 Format:

$ lame -h audio1.wav audio1.mp3

This article was written by SelvaGaneshan. S He is working at bk Systems (p) Ltd, and interested in contributing to the open source.
 
Source: http://www.thegeekstuff.com/2009/05/sound-exchange-sox-15-examples-to-manipulate-audio-files/

Tuesday, July 17, 2012

Cannot open file wav/".wav as tokenstream



Error: PM_WAVE
Cannot open file wav/".wav as tokenstream
Wave load: can't open file "wav/".wav"
Cannot recognize file format or cannot access file: "wav/".wav"
Cannot open file tmp1835.wav as tokenstream
Wave load: can't open file "tmp1835.wav"
Cannot recognize file format or cannot access file: "tmp1835.wav"

Solution:
riff headers are not as standardized as you might think and there are new things added that make previous versions of code fail to read teh .wav files (this is true of some Microsoft code too).

What you need to do is convert your .wav files to something with a more standard .riff header.  The unix program sox can (usually) do this.



Source: http://permalink.gmane.org/gmane.science.tts.festival/3372

Thursday, June 28, 2012

How to set JAVA_HOME environment variable in Ubuntu


One way that you can set your JAVA_HOME variable and add to your PATH, is be doing the folowing.

As 'sudo' open up /etc/bash.bashrc and add the following to the end of the file. 

NOTE: Set the java path to whatever the actual path is on your environment if it does not match /usr/lib/jvm/java

 

    JAVA_HOME=/usr/lib/jvm/java
export JAVA_HOME
PATH=$PATH:$JAVA_HOME/bin
export PATH

 

When you reboot, try running the following:

 

    $ echo $JAVA_HOME
/usr/lib/jvm/java
echo $PATH
[probably lots of paths]:/usr/lib/jvm/java/bin


Thursday, June 7, 2012

Installation of Open Java in ubuntu

Introduction

Java is a technology from Oracle (formerly: Sun Microsystems). There are several implementations, of which five will be discussed here:

  • OpenJDK: The primary goal of the OpenJDK project is to produce an open-source implementation of the Java SE Platform (6 and 7). This is the default version of Java that Ubuntu uses and is the easiest to install.

  • Oracle (Sun) Java 6: Oracle (Sun) Java 6 is the reference implementation for Java 6.

  • Oracle Java 7: Oracle Java 7 is the reference implementation for Java 7.

  • IBM Java: IBM Java is the preferred Java solution on PowerPC machines. It is a reimplementation with a Just-In-Time Compiler. It is only available from IBM's website.

  • GNU Compiler: A Java compiler made by GNU. Only developers should have to install this.

OpenJDK

Installation of Java Runtime Environment

  • Install the openjdk-6-jre package using any installation method.

  • Install the openjdk-7-jre package using any installation method.

Browser plugin

This plugin works with the main browsers: Firefox, Chromium, Google Chrome, and Epiphany.

On Konqueror, go to Settings → Configure Konqueror... and from menu select Java & JavaScript, then tick Enable Java globally option.

SDK (Software Development Kit)

  • Install the openjdk-6-jdk package using any installation method.

  • Install the openjdk-7-jdk package using any installation method.

Source: https://help.ubuntu.com/community/Java

Friday, May 18, 2012

sudo: must be setuid root

This error means: permissions of the sudoers file has been changed.

Solution:

Boot into Recovery Mode and enter a shell prompt. Then run these two commands.
    chown root:root /usr/bin/sudo  chmod 4755 /usr/bin/sudo


To boot in recovery mode :
Hold the shift key down as soon as you poweron the computer. Silly grub2 hides menu by default unless it detects multiple OS.

Check permissions on this:

Code:
ls -la /etc/sudoers  -r--r----- 1 root root 828 2010-08-03 11:19 /etc/sudoers
To modify if permissions are wrong:
Code:
chown root:root /etc/sudoers
Code:
chmod 440 /etc/sudoers
Source: http://ubuntuforums.org/showthread.php?t=1548164

Tuesday, May 15, 2012

How to enable SCIM in Open Office

Open /etc/X11/xinit/xinput.d/scim

The file contents should be  as follows,

XIM=SCIM
XIM_PROGRAM=/usr/bin/scim
XIM_ARGS="-d"
XIM_PROGRAM_SETS_ITSELF_AS_
DAEMON=yes
GTK_IM_MODULE="scim"
QT_IM_MODULE="scim"



How to install SCIM on LINUX

1. Go to System -> Administration-> Synaptic package manager

 search  "scim" and check the checkbox
search "m17n-db" and check the check box a

2. now click on apply option
3. after installation you will get a key board symbol at upper right corner of desktop
   Right click on this symbol, go into
 Global setup
  check the 'Share the same input method among all application'
 press Apply
4. log out and log in
5. now open any text page
press Control+space
if you get a new icon on right down corner of desktop to select language then ok
otherwise right click on text page
Go in Input Method
select Scim input method

Now press Cntl + space , you will get icon.

Enjoy Typing Indian languages

socket:bind failed

Problem:  
 start festival -i --heap 2100000 --serverthen system gives error: socket:bind failed


Solution: 
run   killall -9 festival       several times(normally 4-5) till it says no process to kill

now run the mentioned command it will work

 
    

ORCA : TIMEOUT: something has hung. Aborting

Problem:
boss@cmj-lcg-dellap:~$ orca

** (orca:6754): WARNING **: Trying to register gtype 'WnckWindowState' as enum when in fact it is of type 'GFlags'

** (orca:6754): WARNING **: Trying to register gtype 'WnckWindowActions' as enum when in fact it is of type 'GFlags'

** (orca:6754): WARNING **: Trying to register gtype 'WnckWindowMoveResizeMask' as enum when in fact it is of type 'GFlags'
TIMEOUT: something has hung.  Aborting.


Solution:

Open
/var/lib/python-support/python2.5/orca/settings.py  or  /usr/lib/pymodules/python2.6/orca/settings.py  if none of the above exists then use$ locate settings.py and find the similar path  now inside settings.py  search for timeout you will gettimeoutTime=10  means default value is 10 change it to 30 save the file and now start orca.  

How to install sun-java or sun JDK/JRE in ubuntu

Problem:
Tried to install java using following command:

sudo apt-get install sun-java6-jdk
sudo apt-get install sun-java6-jre
 but got an error message as follows
reading package lists.... done
building dependency tree
reading state information .... done
package sun-java6-jdk is  not available
it has no installation candidate

The solution is :
For Ubuntu 10.04 LTS, the sun-java6 packages have been dropped from the Multiverse section of the Ubuntu archive. It is recommended that you use openjdk-6 instead.
If you can not switch from the proprietary Sun JDK/JRE to OpenJDK, you can install sun-java6 packages from the Canonical Partner Repository. You can configure your system to use this repository via command-line:
     sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
     sudo apt-get update   
     sudo apt-get install sun-java6-jre sun-java6-plugin
     sudo apt-get install sun-java6-jdk 
      sudo update-alternatives --config java
For Ubuntu 10.10, the sun-java6 packages have been dropped from the Multiverse section of the Ubuntu archive. It is recommended that you use openjdk-6 instead.
If you can not switch from the proprietary Sun JDK/JRE to OpenJDK, you can install sun-java6 packages from the Canonical Partner Repository. You can configure your system to use this repository via command-line:
     sudo add-apt-repository "deb http://archive.canonical.com/ maverick partner"
     sudo apt-get update   
     sudo apt-get install sun-java6-jre sun-java6-plugin
        
      sudo apt-get install sun-java6-jdk
      sudo update-alternatives --config java

Source:  https://wiki.ubuntu.com/LucidLynx/ReleaseNotes#Sun%20Java%20moved%20to%20the%20Partner%20repository



If above does not work (for other version of ubuntu) then you can create local repository as follows:




cd ~/
wget https://github.com/flexiondotorg/oab-java6/raw/0.2.1/oab-java6.sh -O oab-java6.sh
chmod +x oab-java6.sh
sudo ./oab-java6.sh

and then run:
sudo apt-get install sun-java6-jdk
sudo apt-get install sun-java6-jre

Source :   https://github.com/flexiondotorg/oab-java6/blob/a04949f242777eb040150e53f4dbcd4a3ccb7568/README.rst

Monday, May 14, 2012

How to enable java in Firefox

How to enable java in Firefox:

Go to www.java.com -> Downloads
download self extracting tar.gz file  follow the instruction below:


working steps:
Source:     https://discussions.nessus.org/thread/4284 

1. Download the latest java runtime either from www.java.com -> Downloads    or    http://www.oracle.com/technetwork/java/javase/downloads/index.html  (for myself it was jre-7u3-linux-i586.tar.gz)



2. plac it in a folder /usr/local/java and extracted it using
 #tar zxvf jre-7u3-linux-i586.tar.gz



3.  #update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jre1.7.0_04/bin/java" 1



4.  #update-alternatives --set java /usr/local/java/jre1.7.0_04/bin/java



Enable and Configure  (Source:   http://java.com/en/download/help/linux_install.xml#selfextracting)

Firefox or Mozilla
To configure the Java Plugin follow these steps:
1. Exit Firefox browser if it is already running.
2. Uninstall any previous installations of Java Plugin.
Only one Java Plugin can be used at a time. When you want to use a different plugin, or version of a plugin, remove the symbolic links to any other versions and create a fresh symbolic link to the new one.
3. Create a symbolic link to the libnpjp2.so file in the browser plugins directory
Go to the plugins sub-directory under the Firefox installation directory
cd <Firefox installation directory>/plugins
Create the symbolic link

ln -s <Java installation directory>/lib/i386/libnpjp2.so      libjavaplugin_oji.so

Note: If you are upgrading your Java version then before creating new symbolic link you should remove old symbolic link to enable latest downloaded Java.

To remove old symbolic link:
type cd <Firefox installation directory>/plugins
rm libjavaplugin_oji.so

Example
If Firefox is installed at this directory:
/usr/lib/<Firefox installation directory>
And if the Java is installed at this directory:
/usr/java/<Java installation directory>
Then type in the terminal window to go to the browser plug-in directory:
/usr/lib/<Firefox installation directory>/plugin
Enter the following command to create a symbolic link to the Java Plug-in for the Mozilla browser.
ln -s /usr/java/<Java installation directory>/lib/i386/libnpjp2.so   libjavaplugin_oji.so


4. Start the Firefox browser, or restart it if it is already up.

In Firefox, type about:plugins in the Location bar to confirm that the Java Plugin is loaded. You can also click the Tools menu to confirm that Java Console is there.

Test Installatio
check if java applet is enabled in the browser by using the following link

In that webpage, in the LIVE box, it should display
“This web browser can indeed run Java applets”
wait for some time for the display to come.