From 15e611a0a2e0f98acd5f508b1b960f8efc74f3c4 Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Mon, 07 Jan 2013 19:13:56 +0000 Subject: clean up encoding; add first part of gst 1.0 play_audio --- diff --git a/lessons/es/alphabet.csv b/lessons/es/alphabet.csv index 4dced1d..be15edf 100644 --- a/lessons/es/alphabet.csv +++ b/lessons/es/alphabet.csv @@ -4,33 +4,33 @@ # These words represent Nivel 1 in Spanish,,,,,, # Use () for highlighted letter in phrase.,,,,,, # letter, phrase, RGB color, color name, vowel or consonant, sound file, -A, (a)ve, #FFFFFF, ave.png, ave.ogg, a.ogg -B, (b)urro, #2080A0, burro.png, burro.ogg, b.ogg -C, (c)onejo, #FFC040, conejo.png, conejo.ogg, c.ogg -D, (d)a(d)o, #20C060, dado.png, dado.ogg, d.ogg -E, (e)l(e)fant(e), #70A9CE, elefante.png, elefante.ogg, e.ogg -F, (f)lor, #C160D2, flor.png, flor.ogg, f.ogg -G, (g)ato, #A0A0A0, gato.png, gato.ogg, g.ogg -H, (h)elado, #FFFFFF, helado.png, helado.ogg, h.ogg -I, (i)gles(i)a, #DE1C23, iglesia.png, iglesia.ogg, i.ogg -J, (j)irafa, #C93C7E, jirafa.png, jirafa.ogg, j.ogg -K, (k)ilo, #FFC040, kilo.png, kilo.ogg, k.ogg -L, (l)oro, #00A0FF, loro.png, loro.ogg, l.ogg -M, (m)esa, #C72020, mesa.png, mesa.ogg, m.ogg -N, (n)ube, #7A6BBD, nube.png, nube.ogg, n.ogg -Ñ, (ñ)andú, #80C040/#C93C7E, nandu.png, nandu.ogg, ny.ogg -O, (o)s(o), #A4221E, oso.png, oso.ogg, o.ogg -P, (p)ato, #A4221E, pato.png, pato.ogg, p.ogg -Q, (q)ueso, #FFC040, queso.png, queso.ogg, q.ogg -R, (r)atón, #F08020, raton.png, raton.ogg, r.ogg -S, (s)apo, #7EC93C, sapo.png, sapo.ogg, s.ogg -T, (t)aza, #EE3C8E, taza.png, taza.ogg, t.ogg -U, (u)va, #00A000, uva.png, uva.ogg, u.ogg -V, (v)aca, #2080A0, vaca.png, vaca.ogg, v.ogg -W, (w)aterpolo, #808080, waterpolo.png, waterpolo.ogg, w.ogg -X, (x)ilófono, #7EC93C, xilofono.png, xilofono.ogg, x.ogg -Y, (y)ate, #BA6C71, yate.png, yate.ogg, y.ogg -# Y, Paragua(y), #DE1C23, paraguay.png, paraguay.ogg, y.ogg -Z, (z)apato, #7EC93C, zapato.png, zapato.ogg, z.ogg -# RR, pe(rr)o, #F08020, perro.png, perro.ogg, rr.ogg -# LL, (ll)ama, #C93C7E, llama.png, llama.ogg, ll.ogg +a, (a)ve, #FFFFFF, ave.png, ave.ogg, a.ogg +b, (b)urro, #2080A0, burro.png, burro.ogg, b.ogg +c, (c)onejo, #FFC040, conejo.png, conejo.ogg, c.ogg +d, (d)a(d)o, #20C060, dado.png, dado.ogg, d.ogg +e, (e)l(e)fant(e), #70A9CE, elefante.png, elefante.ogg, e.ogg +f, (f)lor, #C160D2, flor.png, flor.ogg, f.ogg +g, (g)ato, #A0A0A0, gato.png, gato.ogg, g.ogg +h, (h)elado, #FFFFFF, helado.png, helado.ogg, h.ogg +i, (i)gles(i)a, #DE1C23, iglesia.png, iglesia.ogg, i.ogg +j, (j)irafa, #C93C7E, jirafa.png, jirafa.ogg, j.ogg +k, (k)ilo, #FFC040, kilo.png, kilo.ogg, k.ogg +l, (l)oro, #00A0FF, loro.png, loro.ogg, l.ogg +m, (m)esa, #C72020, mesa.png, mesa.ogg, m.ogg +n, (n)ube, #7A6BBD, nube.png, nube.ogg, n.ogg +ñ, (ñ)andú, #80C040/#C93C7E, nandu.png, nandu.ogg, ny.ogg +o, (o)s(o), #A4221E, oso.png, oso.ogg, o.ogg +p, (p)ato, #A4221E, pato.png, pato.ogg, p.ogg +q, (q)ueso, #FFC040, queso.png, queso.ogg, q.ogg +r, (r)atón, #F08020, raton.png, raton.ogg, r.ogg +s, (s)apo, #7EC93C, sapo.png, sapo.ogg, s.ogg +t, (t)aza, #EE3C8E, taza.png, taza.ogg, t.ogg +u, (u)va, #00A000, uva.png, uva.ogg, u.ogg +v, (v)aca, #2080A0, vaca.png, vaca.ogg, v.ogg +w, (w)aterpolo, #808080, waterpolo.png, waterpolo.ogg, w.ogg +x, (x)ilófono, #7EC93C, xilofono.png, xilofono.ogg, x.ogg +y, (y)ate, #BA6C71, yate.png, yate.ogg, y.ogg +# y, Paragua(y), #DE1C23, paraguay.png, paraguay.ogg, y.ogg +z, (z)apato, #7EC93C, zapato.png, zapato.ogg, z.ogg +# rr, pe(rr)o, #F08020, perro.png, perro.ogg, rr.ogg +# ll, (ll)ama, #C93C7E, llama.png, llama.ogg, ll.ogg diff --git a/page.py b/page.py index 9cfd71b..6931055 100644 --- a/page.py +++ b/page.py @@ -334,7 +334,7 @@ class Page(): self._color_data = [] self._image_data = {} # {letter: [(Sprite, image_sound_path)...]} self._pictures = [] - f = codecs.open(path, encoding='utf-8') + f = open(path) for line in f: if len(line) > 0 and line[0] not in '#\n': words = line.split(', ') @@ -384,8 +384,6 @@ class Page(): def svg_str_to_pixbuf(svg_string): ''' Load pixbuf from SVG string. ''' pl = GdkPixbuf.PixbufLoader.new_with_type('svg') - if type(svg_string) == unicode: - svg_string = svg_string.encode('ascii', 'replace') pl.write(svg_string) pl.close() return pl.get_pixbuf() diff --git a/utils/play_audio.py b/utils/play_audio.py index c06a663..3320b41 100644 --- a/utils/play_audio.py +++ b/utils/play_audio.py @@ -1,10 +1,10 @@ """ aplay.py - refactored based on Jukebox Activity Copyright (C) 2007 Andy Wingo Copyright (C) 2007 Red Hat, Inc. Copyright (C) 2008-2010 Kushal Das Copyright (C) 2010-11 Walter Bender + Copyright (C) 2013-14 Aneesh Dogra """ # This program is free software; you can redistribute it and/or @@ -22,60 +22,59 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 # USA -import os -import subprocess +import gi +gi.require_version('Gst', '1.0') +from gi.repository import GObject, Gst import logging +import time _logger = logging.getLogger('lettermatch-activity') - -GST_PATHS = ['/usr/bin/gst-launch', '/bin/gst-launch', - '/usr/local/bin/gst-launch', - '/usr/bin/gst-launch-1.0', '/bin/gst-launch-1.0', - '/usr/local/bin/gst-launch-1.0', - '/usr/bin/gst-launch-0.10', '/bin/gst-launch-0.10', - '/usr/local/bin/gst-launch-0.10'] - - -def play_audio_from_file(file_path): +def play_audio_from_file(file_path, queue=False): """ Audio media """ + if hasattr(play_audio_from_file, 'player') and \ + play_audio_from_file.player: + if queue: + if hasattr(play_audio_from_file, 'queue'): + if play_audio_from_file.queue and \ + file_path in play_audio_from_file.queue: + # if we already have that file in the queue + # we'll just update the timer. + if hasattr(play_audio_from_file, 'queue_timeout'): + time.sleep(0.01) + GObject.source_remove(play_audio_from_file.queue_timeout) + f = Gst.Format(Gst.Format.TIME) + duration = play_audio_from_file.player.query_duration(f)[0] + timeout = duration / 1000000000. + play_audio_from_file.queue_timeout = \ + GObject.timeout_add(int(timeout * 1000), \ + play_audio_from_file, file_path) + return + else: + play_audio_from_file.queue = [] - if not hasattr(play_audio_from_file, 'gst_launch'): - for path in GST_PATHS: - if os.path.exists(path): - play_audio_from_file.gst_launch = path - _logger.debug(path) - break - - if not hasattr(play_audio_from_file, 'gst_launch'): - _logger.debug('gst-launch not found') - return + time.sleep(0.01) + f = Gst.Format(Gst.Format.TIME) + duration = play_audio_from_file.player.query_duration(f)[0] + timeout = duration / 1000000000. + play_audio_from_file.queue_timeout = GObject.timeout_add( \ + int(timeout * 1000), play_audio_from_file, file_path) + play_audio_from_file.queue.append(file_path) + return + else: + play_audio_from_file.player.set_state(Gst.State.NULL) - command_line = [play_audio_from_file.gst_launch, 'filesrc', - 'location=' + file_path, '! oggdemux', '! vorbisdec', - '! audioconvert', '! alsasink'] - check_output(command_line, 'unable to play audio file %s' % (file_path)) - - -def check_output(command, warning): - ''' Workaround for old systems without subprocess.check_output''' - if hasattr(subprocess, 'check_output'): - try: - output = subprocess.check_output(command) - except subprocess.CalledProcessError: - log.warning(warning) - return None else: - import commands + Gst.init(None) - cmd = '' - for c in command: - cmd += c - cmd += ' ' - (status, output) = commands.getstatusoutput(cmd) - if status != 0: - _logger.warning(warning) - return None - return output + _logger.debug("filesrc location=%s ! decodebin !" \ + " autoaudiosink" % (file_path,)) + play_audio_from_file.player = Gst.parse_launch ( \ + "filesrc location=%s ! decodebin !" \ + " autoaudiosink" % (file_path,)) + if not play_audio_from_file.player: + _logger.warning('unable to play audio file %s' % (file_path)) + else: + play_audio_from_file.player.set_state(Gst.State.PLAYING) -- cgit v0.9.1