changeset 1258:f0bbab217983

speechmusic can now fetch from http Ignore-this: 111d84089591287c786f9119bbe546a darcs-hash:29345c38a1f76d6aaf0f58a34d26c5344b234356
author drewp <drewp@bigasterisk.com>
date Fri, 19 Apr 2019 14:24:09 -0700
parents c0721332a9fe
children 672a3d830e7f
files service/speechMusic/Dockerfile service/speechMusic/makefile service/speechMusic/requirements.txt service/speechMusic/speechMusic.py
diffstat 4 files changed, 17 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/service/speechMusic/Dockerfile	Fri Apr 19 13:51:54 2019 -0700
+++ b/service/speechMusic/Dockerfile	Fri Apr 19 14:24:09 2019 -0700
@@ -11,7 +11,6 @@
 ENV PULSE_SERVER /tmp/pulseaudio
 COPY pulse-client.conf /etc/pulse/client.conf
 COPY *.py req* *.jade ./
-RUN mkdir /sounds
 
 EXPOSE 9049
 
--- a/service/speechMusic/makefile	Fri Apr 19 13:51:54 2019 -0700
+++ b/service/speechMusic/makefile	Fri Apr 19 14:24:09 2019 -0700
@@ -46,7 +46,7 @@
 	docker run --rm -it -p ${PORT}:${PORT} \
           --name=$(JOB)_local \
           --net=host \
-	  --mount type=tmpfs,destination=/sounds,tmpfs-size=52428800 \
+	  --mount type=tmpfs,destination=/tmp,tmpfs-size=52428800 \
           -v /tmp/pulseaudio:/tmp/pulseaudio \
           ${TAG} \
           python speechMusic.py -v
@@ -57,7 +57,7 @@
           --name=$(JOB)_local \
           --net=host \
 	  -v /tmp/pulseaudio:/tmp/pulseaudio \
-	  --mount type=tmpfs,destination=/sounds,tmpfs-size=52428800 \
+	  --mount type=tmpfs,destination=/tmp,tmpfs-size=52428800 \
           --cap-add SYS_PTRACE \
           ${TAG} \
           strace -f -tts 200 python /mnt/speechMusic.py -v
--- a/service/speechMusic/requirements.txt	Fri Apr 19 13:51:54 2019 -0700
+++ b/service/speechMusic/requirements.txt	Fri Apr 19 14:24:09 2019 -0700
@@ -5,4 +5,8 @@
 mock==1.0.1
 pyjade==2.0.2
 Twisted
-pygame==1.9.5
+
+# upgrading to 1.9.5 makes it stop working with pulseaudio
+# (maybe this unversioned one picks the system package which
+# has a better SDL build)
+pygame
--- a/service/speechMusic/speechMusic.py	Fri Apr 19 13:51:54 2019 -0700
+++ b/service/speechMusic/speechMusic.py	Fri Apr 19 14:24:09 2019 -0700
@@ -3,7 +3,7 @@
 play sounds according to POST requests.
 """
 from __future__ import division
-import sys, tempfile
+import sys, tempfile, itertools
 from pyjade.ext.mako import preprocessor as mako_preprocessor
 from mako.lookup import TemplateLookup
 from twisted.internet import reactor
@@ -16,6 +16,7 @@
 import pygame.mixer
 class URIRef(str): pass
 
+soundCount = itertools.count()
 templates = TemplateLookup(directories=['.'],
                            preprocessor=mako_preprocessor,
                            filesystem_checks=True)
@@ -45,14 +46,19 @@
 
     def _getSound(self, uri):
         def done(resp):
-            print('got', len(resp.body))
+            path = '/tmp/sound_%s' % next(soundCount)
+            with open(path, 'w') as out:
+                out.write(resp.body)
+            log.info('write %s bytes to %s', len(resp.body), path)
+            self.buffers[uri] = pygame.mixer.Sound(path)
             
-        return fetch(uri).addCallback(done)
+        return fetch(uri).addCallback(done).addErrback(log.error)
 
     def playEffect(self, uri):
         if uri not in self.buffers:
             self.buffers[uri] = LOADING
-            self._getSound(uri).addCallback(self.playEffect, uri)
+            self._getSound(uri).addCallback(lambda ret: self.playEffect(uri))
+            return
         if self.buffers[uri] is LOADING:
             # The first playback loads then plays, but any attempts
             # during that load are dropped, not queued.