Mercurial > code > home > repos > homeauto
changeset 359:b3959142d7d8
move speech_music into docker and into pygame
Ignore-this: 15260aecbf7fddb75e641b7a853b0281
author | drewp@bigasterisk.com |
---|---|
date | Sun, 09 Sep 2018 04:00:09 -0700 |
parents | 7096dad37074 |
children | 2efa246a65e7 |
files | service/speechMusic/Dockerfile service/speechMusic/Dockerfile.pi service/speechMusic/makefile service/speechMusic/pulse-client.conf service/speechMusic/requirements.txt service/speechMusic/speechMusic.py |
diffstat | 6 files changed, 128 insertions(+), 28 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/service/speechMusic/Dockerfile Sun Sep 09 04:00:09 2018 -0700 @@ -0,0 +1,16 @@ +FROM bang6:5000/base_x86 + +WORKDIR /opt + +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 ./ +COPY pulse-client.conf /etc/pulse/client.conf + +ENV PULSE_SERVER /tmp/pulseaudio +EXPOSE 9049 + +CMD [ "python", "./speechMusic.py" ]
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/service/speechMusic/Dockerfile.pi Sun Sep 09 04:00:09 2018 -0700 @@ -0,0 +1,16 @@ +FROM bang6:5000/base_pi + +WORKDIR /opt + +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 ./ +COPY pulse-client.conf /etc/pulse/client.conf + +ENV PULSE_SERVER /tmp/pulseaudio +EXPOSE 9049 + +CMD [ "python", "./speechMusic.py" ]
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/service/speechMusic/makefile Sun Sep 09 04:00:09 2018 -0700 @@ -0,0 +1,59 @@ +JOB=speech_music +PORT=9049 + +TAG=bang6:5000/${JOB}_x86:latest +TAG_PI=bang6:5000/${JOB}_pi:latest + +prep_ctx: + rm -rf tmp_ctx + mkdir -p tmp_ctx + cp -a Dockerfile* ../../lib/*.py *.py *.jade req* *.conf /my/proj/csigen/generator.py tmp_ctx + mkdir -p tmp_ctx/sound/ + cp '/my/music/entrance/leave.wav' tmp_ctx/sound/ + cp '/my/music/snd/Oxygen/KDE-Im-Highlight-Msg-44100.wav' tmp_ctx/sound/ + cp '/my/music/snd/angel_ogg/angel_question.wav' tmp_ctx/sound/ + cp '/my/music/snd/sampleswap/MELODIC SAMPLES and LOOPS/Acid Jazz Trumpet Lines/acid-jazz-trumpet-11.wav' tmp_ctx/sound/ + cp '/my/music/snd/troy_and_abed_in_the_morning.wav' tmp_ctx/sound/ + cp '/my/music/snd/bxfr/beep1.wav' tmp_ctx/sound/ + cp '/my/music/snd/bxfr/beep2.wav' tmp_ctx/sound/ + +build_image: prep_ctx + docker build --network=host -t ${TAG} tmp_ctx + docker push ${TAG} + rm -rf tmp_ctx + +build_image_pi: prep_ctx + docker build --network=host --file=tmp_ctx/Dockerfile.pi -t ${TAG_PI} tmp_ctx + docker push ${TAG_PI} + rm -rf tmp_ctx + +shell: + docker run --rm -it --cap-add SYS_PTRACE --net=host -v /tmp/pulseaudio:/tmp/pulseaudio ${TAG} /bin/bash + +pactl_test: + docker run --rm -it --cap-add SYS_PTRACE --net=host -v /tmp/pulseaudio:/tmp/pulseaudio ${TAG} pactl stat + +paplay_test_that_is_loud: + docker run --rm -it --cap-add SYS_PTRACE --net=host -v /tmp/pulseaudio:/tmp/pulseaudio ${TAG} paplay /usr/local/lib/python2.7/dist-packages/pygame/examples/data/whiff.wav + +pygame_test: + docker run --rm -it --cap-add SYS_PTRACE --net=host -e SDL_AUDIOSERVER=pulseaudio -v /tmp/pulseaudio:/tmp/pulseaudio ${TAG} python -c 'import os; print os.environ; import pygame.mixer; pygame.mixer.init()' + + +local_run: + docker run --rm -it -p ${PORT}:${PORT} \ + -v `pwd`:/mnt \ + --net=host \ + -v /tmp/pulseaudio:/tmp/pulseaudio \ + ${TAG} \ + python /mnt/speechMusic.py -v + +local_run_strace: + docker run --rm -it -p ${PORT}:${PORT} \ + -v `pwd`:/mnt \ + --net=host \ +-v /tmp/pulseaudio:/tmp/pulseaudio \ + --cap-add SYS_PTRACE \ +-e SDL_AUDIOSERVER=pulse \ + ${TAG} \ + strace -f -tts 200 python /mnt/speechMusic.py -v
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/service/speechMusic/pulse-client.conf Sun Sep 09 04:00:09 2018 -0700 @@ -0,0 +1,8 @@ +default-server = /tmp/pulseaudio + +# Prevent a server running in the container +autospawn = no +daemon-binary = /bin/true + +# Prevent the use of shared memory +enable-shm = false
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/service/speechMusic/requirements.txt Sun Sep 09 04:00:09 2018 -0700 @@ -0,0 +1,8 @@ +Jinja2==2.7 +klein==17.10.0 +Mako==0.8.1 +MarkupSafe==0.18 +mock==1.0.1 +pyjade==2.0.2 +Twisted +pygame
--- a/service/speechMusic/speechMusic.py Sat Sep 08 02:26:23 2018 -0700 +++ b/service/speechMusic/speechMusic.py Sun Sep 09 04:00:09 2018 -0700 @@ -3,21 +3,17 @@ play sounds according to POST requests. """ from __future__ import division -import sys, tempfile, logging, pyjade +import sys, tempfile from pyjade.ext.mako import preprocessor as mako_preprocessor -from mako.template import Template from mako.lookup import TemplateLookup -sys.path.append("python-openal") -import openal from twisted.internet import reactor -sys.path.append("/my/proj/csigen") +sys.path.append("/opt") from generator import tts import xml.etree.ElementTree as ET from klein import Klein from twisted.web.static import File -logging.basicConfig(level=logging.INFO, - format="%(created)f %(asctime)s %(levelname)s %(message)s") -log = logging.getLogger() +from logsetup import log +import pygame.mixer templates = TemplateLookup(directories=['.'], preprocessor=mako_preprocessor, @@ -35,26 +31,24 @@ div.text = sentence speechSecs = tts(root, speechWav.name) - return openal.Buffer(speechWav.name), speechSecs + return pygame.mixer.Sound(speechWav.name), speechSecs class SoundEffects(object): def __init__(self): - # for names to pass to this, see alcGetString with ALC_ALL_DEVICES_SPECIFIER - device = openal.Device() - self.contextlistener = device.ContextListener() # also '/my/music/entrance/%s.wav' then speak "Neew %s. %s" % (sensorWords[data['sensor']], data['name']), - print "loading" + log.info("loading") self.buffers = { - 'leave': openal.Buffer('/my/music/entrance/leave.wav'), - 'highlight' : openal.Buffer('/my/music/snd/Oxygen/KDE-Im-Highlight-Msg-44100.wav'), - 'question' : openal.Buffer('/my/music/snd/angel_ogg/angel_question.wav'), - 'jazztrumpet': openal.Buffer('/my/music/snd/sampleswap/MELODIC SAMPLES and LOOPS/Acid Jazz Trumpet Lines/acid-jazz-trumpet-11.wav'), - 'beep1': openal.Buffer('/my/music/snd/bxfr/beep1.wav'), - 'beep2': openal.Buffer('/my/music/snd/bxfr/beep2.wav'), + 'leave': pygame.mixer.Sound('sound/leave.wav'), + 'highlight' : pygame.mixer.Sound('sound/KDE-Im-Highlight-Msg-44100.wav'), + 'question' : pygame.mixer.Sound('sound/angel_question.wav'), + 'jazztrumpet': pygame.mixer.Sound('sound/acid-jazz-trumpet-11.wav'), + 'troyandabed': pygame.mixer.Sound('sound/troy_and_abed_in_the_morning.wav'), + 'beep1': pygame.mixer.Sound('sound/beep1.wav'), + 'beep2': pygame.mixer.Sound('sound/beep2.wav'), } - print "loaded sounds" + log.info("loaded sounds") self.playingSources = [] self.queued = [] @@ -78,13 +72,11 @@ self.queued.append(reactor.callLater(t, self.playBuffer, buf)) def playBuffer(self, buf): - src = self.contextlistener.get_source() - src.buffer = buf - src.play() + buf.play() - secs = buf.size / (buf.frequency * buf.channels * buf.bits / 8) - self.playingSources.append(src) - reactor.callLater(secs + .1, self.done, src) + secs = buf.get_length() + self.playingSources.append(buf) + reactor.callLater(secs + .1, self.done, buf) return secs def done(self, src): @@ -129,8 +121,9 @@ def stopAll(self, request): self.sfx.stopAll() return "ok" - + +pygame.mixer.init() sfx = SoundEffects() server = Server(sfx) -server.app.run("::", 9049) +server.app.run(endpoint_description=r"tcp6:port=9049:interface=\:\:")