Can I plug in a speaker via USB and play sounds?
Hi Chris, while it's not supported by our libraries, yes I think it's possible, it's supported by pygame which is available under the hood.
Add a wav file to the project (I used air_raid.wav), and use this program.
import tingbot from tingbot import * import pygame pygame.mixer.init() air_raid_sound = pygame.mixer.Sound('air_raid.wav') @left_button.press def p(): air_raid_sound.play() @every(seconds=1.0/30) def loop(): screen.fill(color='black') screen.text('Press the left button!') tingbot.run()
I think USB audio devices are selected as soon as they are plugged in, so this should work as expected on the Tingbot.
Quick note - the bundled version of Pygame on the Mac doesn't support audio, so you'll have to test this on the Tingbot.
Added a wave file. changed the filename to match my wav file. Then uploaded code to tingbot. Didn't work on the tingbot. I am using a Patronics Blackwire 315.1 USB headset plugged into the Tingbot for sound. Headset specs here
Here is my code:
Quick update. I opened my Tingbot and plugged in directly to the 3.5mm jack and your code worked. Do i need an Should I be using an external usb sound card?
Thanks for that @Chris, confirms that we need to sort out the audio device selection.
What version of pygame are you running on the Tingbot?
@Chris we're running pygame 1.9.2 in the bot I think. I've actually been doing a bit of work on this over the weekend, I'm preparing an OS update that will enable support for the USB sound devices. Stay tuned!
@Chris Joe's updated Tingbot OS and Tide for USB sound device support
You'll need to update Tide to v0.5.5 and Tingbot OS to v1.2.3
Docs can be found here: http://docs.tingbot.com/projects/tingbot-python/en/latest/sound.html
Let us know how you get on!
Awesome guys. Working perfectly on my Mac now. I have an external USB sound card on order to test USB sound on the Tingbot. My hypothesis is that this will work: http://www.staples.com/Sabrent-AU-MMSA-USB-2-0-3D-External-Sound-Box-Adapter-Black/product_IM1YP5954?akamai-feo=off
I will let you know how it goes.
Ok. Totally working on the TingBot using the USB audio adapter.
One more question. Is there a way to turn up the volume?
I could do it on the 3.1mm jack with the following at the command line:
amixer sset PCM,0 90%
Is there something similar for the USB port?
I bit more. Was able to do it with 'alsamixer -c 1'
Then ''sudo alsactl store"