Can't simultaneously read/write from ossaudio dsp device

Tito generic_user25 at yahoo.com
Mon Mar 13 08:55:33 EST 2006


I got it working!  There was another thread http://tinyurl.com/pebqc on
this group where someone had the same problem.  I changed my code to
the following:

from twisted.internet.task import LoopingCall
from twisted.internet import reactor
import os, sys, wave, audioop

"""
While playing the contents of test1.wav,  talk into the mic
and have the audio recorded into /tmp/out.wav
"""

def playnlisten_out():
    audio = wavin.readframes(1024)
    stereoaudio = audioop.tostereo(audio, 2, 1, 1)
    dspout.write(stereoaudio)

def playnlisten_in():
    audio = dspin.read(640)
    wavout.write(audio)

def both():
    playnlisten_out()
    playnlisten_in()

dspout = ossaudiodev.open('/dev/dsp', 'w')    # 2 file handles
dspin = ossaudiodev.open('/dev/dsp', 'r')

wavin = wave.open("test1.wav", "r")
wavout = wave.open("/tmp/out.wav", "w")

both_loop = LoopingCall(both)
both_loop.start(0.02)

reactor.run()

and it worked as expected.  I did not need to mess around with
/dev/mixer.




More information about the Python-list mailing list