Mercurial > code > home > repos > homeauto
changeset 454:ccde9f432e4e
WIP speechmusic to load from http, but pulseaudio out is broken
Ignore-this: 28a41741b1f33114348f5ec6e7b4bef9
author | drewp@bigasterisk.com |
---|---|
date | Fri, 19 Apr 2019 13:51:54 -0700 |
parents | 9fd92202c886 |
children | 7e09c0d0a86e |
files | service/speechMusic/Dockerfile service/speechMusic/Dockerfile.pi service/speechMusic/makefile service/speechMusic/requirements.txt service/speechMusic/speechMusic.py |
diffstat | 5 files changed, 42 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/service/speechMusic/Dockerfile Fri Apr 19 11:57:51 2019 -0700 +++ b/service/speechMusic/Dockerfile Fri Apr 19 13:51:54 2019 -0700 @@ -2,15 +2,17 @@ WORKDIR /opt +RUN apt-get update RUN apt-get install --yes libopenal1 libogg0 pulseaudio-utils python-pygame festival sox COPY requirements.txt ./ RUN pip install -r requirements.txt -COPY sound sound -COPY *.py req* *.jade ./ +ENV SDL_AUDIODRIVER pulse +ENV PULSE_SERVER /tmp/pulseaudio COPY pulse-client.conf /etc/pulse/client.conf +COPY *.py req* *.jade ./ +RUN mkdir /sounds -ENV PULSE_SERVER /tmp/pulseaudio EXPOSE 9049 CMD [ "python", "./speechMusic.py" ]
--- a/service/speechMusic/Dockerfile.pi Fri Apr 19 11:57:51 2019 -0700 +++ b/service/speechMusic/Dockerfile.pi Fri Apr 19 13:51:54 2019 -0700 @@ -13,5 +13,6 @@ ENV PULSE_SERVER /tmp/pulseaudio EXPOSE 9049 +RUN mkdir /sounds CMD [ "python", "./speechMusic.py" ]
--- a/service/speechMusic/makefile Fri Apr 19 11:57:51 2019 -0700 +++ b/service/speechMusic/makefile Fri Apr 19 13:51:54 2019 -0700 @@ -23,7 +23,14 @@ docker push ${TAG_PI} shell: build_image - docker run --rm -it --cap-add SYS_PTRACE --net=host -v /tmp/pulseaudio:/tmp/pulseaudio ${TAG} /bin/bash + docker run --rm -it \ + --cap-add SYS_PTRACE \ + --name=$(JOB)_shell \ + --mount type=tmpfs,destination=/tmp,tmpfs-size=52428800 \ + --net=host \ + -v /tmp/pulseaudio:/tmp/pulseaudio \ + ${TAG} \ + /bin/bash pactl_test: build_image docker run --rm -it --cap-add SYS_PTRACE --net=host -v /tmp/pulseaudio:/tmp/pulseaudio ${TAG} pactl stat @@ -37,12 +44,12 @@ local_run: build_image docker run --rm -it -p ${PORT}:${PORT} \ - -v `pwd`:/mnt \ --name=$(JOB)_local \ --net=host \ + --mount type=tmpfs,destination=/sounds,tmpfs-size=52428800 \ -v /tmp/pulseaudio:/tmp/pulseaudio \ ${TAG} \ - python /mnt/speechMusic.py -v + python speechMusic.py -v local_run_strace: build_image docker run --rm -it -p ${PORT}:${PORT} \ @@ -50,8 +57,8 @@ --name=$(JOB)_local \ --net=host \ -v /tmp/pulseaudio:/tmp/pulseaudio \ + --mount type=tmpfs,destination=/sounds,tmpfs-size=52428800 \ --cap-add SYS_PTRACE \ - -e SDL_AUDIOSERVER=pulse \ ${TAG} \ strace -f -tts 200 python /mnt/speechMusic.py -v
--- a/service/speechMusic/requirements.txt Fri Apr 19 11:57:51 2019 -0700 +++ b/service/speechMusic/requirements.txt Fri Apr 19 13:51:54 2019 -0700 @@ -5,4 +5,4 @@ mock==1.0.1 pyjade==2.0.2 Twisted -pygame +pygame==1.9.5
--- a/service/speechMusic/speechMusic.py Fri Apr 19 11:57:51 2019 -0700 +++ b/service/speechMusic/speechMusic.py Fri Apr 19 13:51:54 2019 -0700 @@ -7,13 +7,14 @@ from pyjade.ext.mako import preprocessor as mako_preprocessor from mako.lookup import TemplateLookup from twisted.internet import reactor -sys.path.append("/opt") +from cyclone.httpclient import fetch from generator import tts import xml.etree.ElementTree as ET from klein import Klein from twisted.web.static import File from logsetup import log import pygame.mixer +class URIRef(str): pass templates = TemplateLookup(directories=['.'], preprocessor=mako_preprocessor, @@ -30,23 +31,33 @@ div.set("TYPE", "sentence") div.text = sentence - speechSecs = tts(root, speechWav.name) + speechSecs = tts(speech, speechWav.name) return pygame.mixer.Sound(speechWav.name), speechSecs +class LOADING(object): pass + class SoundEffects(object): def __init__(self): - - # also '/my/music/entrance/%s.wav' then speak "Neew %s. %s" % (sensorWords[data['sensor']], data['name']), - - log.info("loading") - self.buffers = {name.rsplit('.', 1)[0]: pygame.mixer.Sound('sound/%s' % name) for name in os.listdir('sound')} - log.info("loaded sounds") + self.buffers = {} # URIRef : pygame.mixer.Sound self.playingSources = [] self.queued = [] self.volume = 1 # level for the next sound that's played (or existing instances of the same sound) - def playEffect(self, name): - snd = self.buffers[name] + def _getSound(self, uri): + def done(resp): + print('got', len(resp.body)) + + return fetch(uri).addCallback(done) + + def playEffect(self, uri): + if uri not in self.buffers: + self.buffers[uri] = LOADING + self._getSound(uri).addCallback(self.playEffect, uri) + if self.buffers[uri] is LOADING: + # The first playback loads then plays, but any attempts + # during that load are dropped, not queued. + return + snd = self.buffers[uri] snd.set_volume(self.volume) return self.playBuffer(snd) @@ -85,6 +96,7 @@ self.playingSources.pop().stop() for q in self.queued: q.cancel() + # doesn't cover the callLater ones class Server(object): app = Klein() @@ -114,8 +126,8 @@ return "ok" @app.route('/volume', methods=['PUT']) - def effect(self, request, name): - self.sfx.setVolume(float(request.args['msg'][0])) + def volume(self, request, name): + self.sfx.setVolume(float(request.args['v'][0])) return "ok" @app.route('/stopAll', methods=['POST'])