changeset 453:9fd92202c886

WIP updating to read sounds from http Ignore-this: 9a7aa4cdd539ed1ace268f42ad76021a
author drewp@bigasterisk.com
date Fri, 19 Apr 2019 11:57:51 -0700
parents a8073bcddd8b
children ccde9f432e4e
files service/speechMusic/Dockerfile.pi service/speechMusic/makefile service/speechMusic/speechMusic.py
diffstat 3 files changed, 41 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/service/speechMusic/Dockerfile.pi	Fri Apr 19 04:18:44 2019 -0700
+++ b/service/speechMusic/Dockerfile.pi	Fri Apr 19 11:57:51 2019 -0700
@@ -2,6 +2,7 @@
 
 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
--- a/service/speechMusic/makefile	Fri Apr 19 04:18:44 2019 -0700
+++ b/service/speechMusic/makefile	Fri Apr 19 11:57:51 2019 -0700
@@ -8,52 +8,61 @@
 	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
+
+push_image: build_image
 	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
+
+push_image_pi: build_image_pi
 	docker push ${TAG_PI}
-	rm -rf tmp_ctx
 
-shell:
+shell: build_image
 	docker run --rm -it --cap-add SYS_PTRACE --net=host -v /tmp/pulseaudio:/tmp/pulseaudio ${TAG} /bin/bash
 
-pactl_test:
+pactl_test: build_image
 	docker run --rm -it --cap-add SYS_PTRACE --net=host -v /tmp/pulseaudio:/tmp/pulseaudio ${TAG} pactl stat
 
-paplay_test_that_is_loud:
+paplay_test_that_is_loud: build_image
 	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:
+pygame_test: build_image
 	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:
+local_run: build_image
 	docker run --rm -it -p ${PORT}:${PORT} \
           -v `pwd`:/mnt \
+          --name=$(JOB)_local \
           --net=host \
           -v /tmp/pulseaudio:/tmp/pulseaudio \
           ${TAG} \
           python /mnt/speechMusic.py -v
 
-local_run_strace:
+local_run_strace: build_image
 	docker run --rm -it -p ${PORT}:${PORT} \
           -v `pwd`:/mnt \
+          --name=$(JOB)_local \
           --net=host \
--v /tmp/pulseaudio:/tmp/pulseaudio \
+	  -v /tmp/pulseaudio:/tmp/pulseaudio \
           --cap-add SYS_PTRACE \
--e SDL_AUDIOSERVER=pulse \
+	  -e SDL_AUDIOSERVER=pulse \
           ${TAG} \
           strace -f -tts 200 python /mnt/speechMusic.py -v
+
+fresh_sudo:
+	sudo -v
+
+redeploy: fresh_sudo push_image push_image_pi
+	sudo /my/proj/ansible/playbook -l with_speakers -t $(JOB)
+	supervisorctl -s http://dash:9001/ restart $(JOB)_$(PORT)
+	supervisorctl -s http://slash:9001/ restart $(JOB)_$(PORT)
+	supervisorctl -s http://bed:9001/ restart $(JOB)_$(PORT)
+	supervisorctl -s http://living:9001/ restart $(JOB)_$(PORT)
+	supervisorctl -s http://kitchen:9001/ restart $(JOB)_$(PORT)
+
--- a/service/speechMusic/speechMusic.py	Fri Apr 19 04:18:44 2019 -0700
+++ b/service/speechMusic/speechMusic.py	Fri Apr 19 11:57:51 2019 -0700
@@ -39,21 +39,16 @@
         # also '/my/music/entrance/%s.wav' then speak "Neew %s. %s" % (sensorWords[data['sensor']], data['name']),
 
         log.info("loading")
-        self.buffers = {
-            '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'),
-        }
+        self.buffers = {name.rsplit('.', 1)[0]: pygame.mixer.Sound('sound/%s' % name) for name in os.listdir('sound')}
         log.info("loaded sounds")
         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):
-        return self.playBuffer(self.buffers[name])
+        snd = self.buffers[name]
+        snd.set_volume(self.volume)
+        return self.playBuffer(snd)
 
     def playSpeech(self, txt, preEffect=None, postEffect=None, preEffectOverlap=0):
         buf, secs = makeSpeech(txt)
@@ -112,9 +107,15 @@
         self.sfx.playSpeech(request.args['msg'][0])
         return "ok"
 
-    @app.route('/effects/<string:name>', methods=['POST'])
+    @app.route('/playSound', methods=['POST'])
+    def effect(self, request):
+        uri = request.args['uri'][0]
+        self.sfx.playEffect(uri)
+        return "ok"
+
+    @app.route('/volume', methods=['PUT'])
     def effect(self, request, name):
-        self.sfx.playEffect(name)
+        self.sfx.setVolume(float(request.args['msg'][0]))
         return "ok"
 
     @app.route('/stopAll', methods=['POST'])