Finally I found how to use my USB Webcam on Scratch in effective way for recording/playing sound and taking photos. Especially this is very nice in classroom or coder club. I have Raspberry Pi classes of 70 kids age from 9 to 13 to code to learn Scratch, Sonic Pi, Minecraft-Scratch, SunVox or others with GPIO tinkering.
You know, in this situation I have to be cost-sensitive, and to do things in easier and fun method.
Situation:
I would like to use the onboard audio jack to play sound thru, and would like to add an USB webcam, cheap and nice "UVC-compatible" or USB Video Class device to record sound, and of course, also take photos with. I have Logitech C-270 and C-310. The C-270 is cheaper and good enough.
Problem:
I always sadly see the message "Sound Recorder: unable to connect to input device " and no sound recording on Scratch.
Solution:
Survived form the deep forest of ALSA conf, I found the recipe. Only you have to do is to edit the file named ".asoundrc" at home directory or /home/pi/.asoundrc or ~/.asoundrc.
$ nano .asoundrc
Code: Select all
pcm.!default {
type asym
playback.pcm {
type hw
card 0
}
capture.pcm {
type hw
card 1
}
}
ctl.!default {
type hw
card 0
}
Hey! Now I can use the webcam as a recorder! Bonus:
Taking a photo as a new costume of a sprite:
You can use the webcam to take photos in Scratch. Just go to the Costume tab then you will find the [Camera] button! Taking photos in the script:
1. Start the GPIO server by [ broadcast ( gpioserveron ) ] block.
2. Take a photo by [ broadcast ( photo ) ] block. 3. The photo taken is stored as a new costume.
Enjoy!
naohiro