I have got a bit further with the microphone pass-through.
Firstly I tried writing a program using python and pyaudio. While I can record and play back sound simultaneously, the playback of the recorded sound is very choppy (there is minimal lag however!). This isn't really surprising as all the program is doing is sampling a chunk of data from the microphone (512 bytes by default) and then playing it on the sound card.. It sounds "choppy" because it's chopped up!
One good thing though, is I can play back an additional sound at the same time and this comes out clearly. Source-code available if anyone wants. So choppy voice but clear playback of music.
A faster solution came with alsaloop. You'll need to install the alsa-tools (sudo apt-get install alsa-tools). Using this we can "bridge" the input device to the sound card:
Code: Select all
alsaloop -C hw:1,0 -P hw: 0,0 -c 1 -t 20000
This tells alsaloop that the capture device is on hw:1,0 (it probably is if you plugged in a USB mic), the playback is 0,0 (which it also probably is, but you can check with aplay -l and record -l for capture). I have set a latency in this example of 20000 ms, much less than that and you do start to get underruns (but it also seems to perform! Try it with a latency of 1000. Other than the errors on screen, it seems to be achieving this?!
You can run alsaloop as a daemon with -d and this works fine too.
So, almost immediate and clean playback of microphone input in the background...
Even better.. we can now playback another sound using aplay or VCN player from the desktop (yes, you can happily run the desktop). This works too!... UNTIL that sound finishes. Then ALSA or something seems to crash, taking out the audio until reboot.
So we're almost there in terms of karaoke functionality.
I'm going to look into this further as PyKaraoke is actually just a trio of python modules and could be a very flexible option. But there are alternatives.
XBMC supports karaoke files and apparently has pass-through microphone capability. Will test tonight on OpenELEC and XBian.
There is also a plugin for XBMC which looks promising, called Mikey's Karaoke which I will also test.
There are also a number of other packages:
OSD Lyrics. A desktop app that plays just the lyrics Karaoke-style. This is probably still going to leave me with the current problem of mic pass-through and additional music playback.
Ultrastar (looks like a compile from source job here).
Anyone seen any others worth looking at?
Have more FUN with your Pi. Visit www.pi-fun.com