Newbie SWMixer / numpy help - AssertionError

P

Peter Chant

Hello,

I'm a bit of a python newby. I want to play and record sound
simultaneously. SWMixer seems able to do this but the examples use WAV
files. I'm trying to play a test tone. Can anyone give me a steer as to
why this fails?

import sys
import swmixer
import numpy


swmixer.init(samplerate=44100, chunksize=1024, stereo=False,
microphone=True)
#snd = swmixer.Sound("test1.wav")
time = 1
freq = 440
time = numpy.linspace(0,1,44100*time) # 44100 numbers between 0 and 1
tone_data = numpy.sin(time*2*numpy.pi*freq) # A above Middle C
snd = swmixer.Sound(tone_data)

snd.play(loops=-1)

I know this may be in a little at the deep end for someone who has just
started to learn python, but I find I learn a lot faster if I try to do
something that is useful.

Pete
 
R

Robert Kern

Hello,

I'm a bit of a python newby. I want to play and record sound
simultaneously. SWMixer seems able to do this but the examples use WAV
files. I'm trying to play a test tone. Can anyone give me a steer as to
why this fails?

Looking at the SWMixer docs, you probably want

snd = swmixer.Sound(data=tone_data)

Well, sort of. You probably need to scale your data and convert it to int16
format. It's currently in floating point format.

When asking about why something fails, it helps a lot if you specify exactly how
it fails and what you expected to happen. Copy-and-paste any error messages exactly.

If you need more help with SWMixer's API, I recommend asking the author. It's
not in widespread use, so he can probably give you better and faster help than
we can.

If you need more help with numpy, specifically, you can ask on the
numpy-discussion mailing list. numpy *is* in widespread use, but there's a
higher concentration of helpful numpy users over there.

http://www.scipy.org/Mailing_Lists

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
 
P

Peter Chant

Robert said:
snd = swmixer.Sound(data=tone_data)

Well, sort of. You probably need to scale your data and convert it to
int16 format. It's currently in floating point format.

Done and working, thanks. As "file" was not needed for file="test.wav" I
assumed the data prefix for data was not essential.
When asking about why something fails, it helps a lot if you specify
exactly how it fails and what you expected to happen. Copy-and-paste any
error messages exactly.
OK


If you need more help with SWMixer's API, I recommend asking the author.
It's not in widespread use, so he can probably give you better and faster
help than we can.

If you need more help with numpy, specifically, you can ask on the
numpy-discussion mailing list. numpy *is* in widespread use, but there's a
higher concentration of helpful numpy users over there.

http://www.scipy.org/Mailing_Lists

Most useful response, thanks.

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,787
Messages
2,569,627
Members
45,329
Latest member
InezZ76898

Latest Threads

Top