pythonsox

sox create and play tone only on left or right channel


I am trying to create a tone in python and play it only on either the left channel or right channel. I can't figure out how to specify playing on the chosen channel.

Here is my code so far:

import os

frequency = 1000 #hz

duration = 2000 #milliseconds

os.system('play -n synth %s sin %s' % (duration/1000, frequency))

I have experimented with "remix" but haven't been successful.

Thanks for the help!


Solution

  • I suggest getting sox to output what you want first before adding to your python code. This should do what you want (left first, then right).

    play -n -c 2 synth 2 sin 1000 remix 1 0
    play -n -c 2 synth 2 sin 1000 remix 0 1
    

    It's possible you might also have an issue with the default device for sox. play is simply an alias for sox -d i.e. using the default device for output. To check this, or if you want the output to go to a file, you can use this:

    sox -n -c 2 left.wav synth 2 sin 1000 remix 1 0
    sox -n -c 2 right.wav synth 2 sin 1000 remix 0 1
    

    Your python code could incorporate this like so:

    import os    
    
    frequency = 1000 #hz
        
    duration = 2000 #milliseconds
        
    os.system('play -n -c 2 synth %s sin %s remix 1 0' % (duration/1000, frequency))