Sound Input ~ Microphone

Hello Elysiun …

I was wondering about the sound input possibility in BGE …

i want to move a cube with the a velocity of my voice amplitude …

is this possible and how ?

Hello, my friend. I see you’ve changed your name :wink:

BGE doesn’t have any sound input by itself, but you can gather data from the microphone using Python. I’ve never done this myself, but I see that PyAudio is capable of recording microphone data and that SoundAnalyse can distinguish volume and pitch of voices.

PyAudio: http://people.csail.mit.edu/hubert/pyaudio/
SoundAnalyse: http://code.google.com/p/pygalaxy/wiki/SoundAnalyse

You could use the two in combination to analyze the sound input and calculate a velocity for the cube.

if possible please post your results, it sounds interesting :slight_smile:

I looked into it a little further, and you will need NumPy installed in order to use PyAudio. There is a pre-compiled Windows binary of NumPy, it would seem, but Linux users like me will have to compile the library themselves.

NumPy: http://numpy.scipy.org/

Edit: Nevermind… it seems that NumPy comes installed with Python on my Linux distro. I ran some tests, and I am able to read input from the microphone and print out information about the amplitude from Python. I haven’t tried it in Blender yet.

I looked into it a little further, and you will need NumPy installed in order to use PyAudio. There is a pre-compiled Windows binary of NumPy, it would seem, but Linux users like me will have to compile the library themselves.

NumPy: http://numpy.scipy.org/

enzo , would this be live or a wav file ?

It is live. If you download the source code for PyAudio, you will find a directory called “tests” which has some demonstration scripts in it. The “record.py” script shows how to capture from the microphone. Of course, the microphone must be turned on in the volume control recording panel of your operating system first.

I was able to get sound recording working inside of Blender using these modules, but it slows down the game to 12 frames per second (I normally get about 900 frames per second on an empty scene). I’m trying different methods of running the script to try to get faster speed, but I have had no success yet. I will keep you updated.

Well, I feel silly.

I was opening the microphone stream and closing it again on every frame. Of course it was running at 12 frames per second.

Now I have a class set up to open the microphone input stream when the game starts and to close it automatically when the game quits. During the actual game I am simply reading data from the stream. I was able to read 512 bit chunks of audio data at 86 frames per second, but that would probably end up being rather slow on most computers, so I set it to read 64 bit chunks instead, and I was getting a solid 600 frames per second.

As a test, I did move a cube with my voice, as you were hoping to do. I will post some demo .blends and instructions sometime tomorrow.

all right! thanks dude

I posted information and a demo .blend here:

http://blenderartists.org/forum/showthread.php?t=151392

1 Like

that’s a distinguished .blend …
i’m amazed with your programming skills .

Very nice, man. Kudos.

where is this blend file now ? it doesnt exist on blenderartists anymore

can somebody please help