[Parley-devel] first scriptlet for voice retrieval
Eitzenberger Thomas
eth at gmx.at
Sun Mar 29 11:57:10 CEST 2009
Hello honored listmembers,
attached (at the end of mail body) a first PREALPHA ALPHA draft scriptlet to
retrieve and play the sound file of wiktionary for a given word.
Any feedback appreciated if I am on the right track or going in total wrong
direction
PRECONDITIONS at this moment:
mplayer installed
mwclient python library downloaded and installed (either in system or in same
directory as the script)
WHY ?
mplayer is just a temporary workaround as the Python QT4 bindings on ubuntu
(and maybe on others too) are not bundling the Phonon package --- Need to
clarify why !
mwclient is a MIT licensed pacakge that supports requesting info from
mediawiki sites. This software allows easily to retrieve the ogg files and
reduces the code base for the plugin dramatically :O)
TODO
o integrate with Phonon to get rid of external app
o integrate with Parley API
o make it configurable based on config file
o support also subcategories (de includes de, de-at, de-ch, .....; en includes
en-us, en-gb,.....)
o error handling in case there is no such file
o polishing for a first alpha release
USAGE
python script.py word twodigit-langcode
example:
python script.py introduce en
SCRIPT
-------------------------------
import mwclient
import sys
import os
lang = sys.argv[2]
word = sys.argv[1]
wikilang = ''
wikilangcode = ''
if (string.lower(lang[:2]) == 'en'):
wikilang = 'English'
wikilangcode = 'En-us'
if (string.lower(lang[:2]) == 'fr'): wikilang = 'French'
if (string.lower(lang[:2]) == 'de'):
wikilang = 'German'
wikilangcode = 'De'
commons = mwclient.Site('commons.wikimedia.org')
image = commons.Images[wikilangcode + '-' + word + '.ogg']
print 'Image', image.name.encode('utf-8')
filename = u"/tmp/%s" % image.name[5:]
saveas = open(filename,'w')
remote = image.download()
saveas.write(remote.read())
saveas.close()
os.execlp('mplayer', 'mplayer', filename)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.kde.org/pipermail/parley-devel/attachments/20090329/5e908e51/attachment.htm
More information about the Parley-devel
mailing list