Reply
Thread Tools
Posts: 662 | Thanked: 238 times | Joined on Jul 2007
#1
Hello!

I haven't been able to find anything that works to simply play a wav on maemo, I've tried...

import pygame
pygame.init()
sound = pygame.mixer.Sound("/home/user/tada.wav")
sound.play()
and even tried with gstreamer...

import pygst
pygst.require('0.10')
import gst
import gobject, sys

def play_uri(uri):
" play an uri like tada.wav "

player = gst.element_factory_make("playbin", "player")

print 'Playing:', uri
player.set_property('uri', uri)
player.set_state(gst.STATE_PLAYING)


play_uri("/home/user/tada.wav")
(Everything is indented from "play a uri like..." to player.set_state

But nothing seems to work... could someone please just show me a snippet on how to play a wav on the tablets? Thats it, no need to stop or pause or anything else, just play it. It would be greatly appreciated!

Thanks.
 

The Following 2 Users Say Thank You to Aisu For This Useful Post:
pycage's Avatar
Posts: 3,404 | Thanked: 4,474 times | Joined on Oct 2005 @ Germany
#2
To me it looks like your programs exit before they can play the sound. Try using
import gtk; gtk.main()
at the end of your gstreamer code. This will enter the GTK mainloop, and thus also the glib mainloop which is used by gstreamer.
 
Posts: 662 | Thanked: 238 times | Joined on Jul 2007
#3
Thanks a lot, but running

import pygst
pygst.require('0.10')
import gst
import gobject, sys

def play_uri(uri):
" play an uri like tada.wav "

player = gst.element_factory_make("playbin", "player")

print 'Playing:', uri
player.set_property('uri', uri)
player.set_state(gst.STATE_PLAYING)


play_uri("/home/user/tada.wav")
import gtk; gtk.main()
Gets this:

Nokia-770-36:/home/user# python sound.py
Playing: /home/user/tada.wav
python[2166]: GLIB CRITICAL ** GStreamer - gst_element_make_from_uri: assertion `gst_uri_is_valid (uri)' failed
python[2166]: GLIB CRITICAL ** GStreamer - gst_uri_get_protocol: assertion `gst_uri_is_valid (uri)' failed
Any ideas...?
 
Posts: 662 | Thanked: 238 times | Joined on Jul 2007
#4
Update:

The error messages stopped when I added the file:// prefix before the uri, ie:

play_uri("file:///home/user/tada.wav")
But still no sound...
 
darethehair's Avatar
Posts: 273 | Thanked: 104 times | Joined on Mar 2007 @ Manitoba, Canada
#5
Aisu:

I am just a learner myself, but I have dabbled with sound in pygame just as you tried. I reduced my (working) program to a bare minimum, and for me on my desktop python (not yet confirmed in maemo python) it works fine for me as long as the python program itself runs long enough to actually *play* the sound file. To artificially make your program do the same, try adding this final line to your python file:

pygame.time.delay(5000)

For my actual program, it doesn't need this because it is a non-serial program that constantly polls the keys being pressed -- if you know what I mean.
 

The Following User Says Thank You to darethehair For This Useful Post:
Posts: 662 | Thanked: 238 times | Joined on Jul 2007
#6
Thank you, thank you, thank you! Perfect! It works! Now I just have to find the right sounds
 
Reply


 
Forum Jump


All times are GMT. The time now is 14:11.