Mercurial > code > home > repos > homeauto
comparison service/speechMusic/speechMusic.py @ 1256:a723efcf6476
WIP updating to read sounds from http
Ignore-this: 9a7aa4cdd539ed1ace268f42ad76021a
darcs-hash:accb28064b93d750ff072a02e480effad3ca0e42
author | drewp <drewp@bigasterisk.com> |
---|---|
date | Fri, 19 Apr 2019 11:57:51 -0700 |
parents | 1fe67fedf5ac |
children | ccde9f432e4e |
comparison
equal
deleted
inserted
replaced
1255:9e1f067010b3 | 1256:a723efcf6476 |
---|---|
37 def __init__(self): | 37 def __init__(self): |
38 | 38 |
39 # also '/my/music/entrance/%s.wav' then speak "Neew %s. %s" % (sensorWords[data['sensor']], data['name']), | 39 # also '/my/music/entrance/%s.wav' then speak "Neew %s. %s" % (sensorWords[data['sensor']], data['name']), |
40 | 40 |
41 log.info("loading") | 41 log.info("loading") |
42 self.buffers = { | 42 self.buffers = {name.rsplit('.', 1)[0]: pygame.mixer.Sound('sound/%s' % name) for name in os.listdir('sound')} |
43 'leave': pygame.mixer.Sound('sound/leave.wav'), | |
44 'highlight' : pygame.mixer.Sound('sound/KDE-Im-Highlight-Msg-44100.wav'), | |
45 'question' : pygame.mixer.Sound('sound/angel_question.wav'), | |
46 'jazztrumpet': pygame.mixer.Sound('sound/acid-jazz-trumpet-11.wav'), | |
47 'troyandabed': pygame.mixer.Sound('sound/troy_and_abed_in_the_morning.wav'), | |
48 'beep1': pygame.mixer.Sound('sound/beep1.wav'), | |
49 'beep2': pygame.mixer.Sound('sound/beep2.wav'), | |
50 } | |
51 log.info("loaded sounds") | 43 log.info("loaded sounds") |
52 self.playingSources = [] | 44 self.playingSources = [] |
53 self.queued = [] | 45 self.queued = [] |
46 self.volume = 1 # level for the next sound that's played (or existing instances of the same sound) | |
54 | 47 |
55 def playEffect(self, name): | 48 def playEffect(self, name): |
56 return self.playBuffer(self.buffers[name]) | 49 snd = self.buffers[name] |
50 snd.set_volume(self.volume) | |
51 return self.playBuffer(snd) | |
57 | 52 |
58 def playSpeech(self, txt, preEffect=None, postEffect=None, preEffectOverlap=0): | 53 def playSpeech(self, txt, preEffect=None, postEffect=None, preEffectOverlap=0): |
59 buf, secs = makeSpeech(txt) | 54 buf, secs = makeSpeech(txt) |
60 t = 0 | 55 t = 0 |
61 if preEffect: | 56 if preEffect: |
110 @app.route('/speak', methods=['POST']) | 105 @app.route('/speak', methods=['POST']) |
111 def speak(self, request): | 106 def speak(self, request): |
112 self.sfx.playSpeech(request.args['msg'][0]) | 107 self.sfx.playSpeech(request.args['msg'][0]) |
113 return "ok" | 108 return "ok" |
114 | 109 |
115 @app.route('/effects/<string:name>', methods=['POST']) | 110 @app.route('/playSound', methods=['POST']) |
111 def effect(self, request): | |
112 uri = request.args['uri'][0] | |
113 self.sfx.playEffect(uri) | |
114 return "ok" | |
115 | |
116 @app.route('/volume', methods=['PUT']) | |
116 def effect(self, request, name): | 117 def effect(self, request, name): |
117 self.sfx.playEffect(name) | 118 self.sfx.setVolume(float(request.args['msg'][0])) |
118 return "ok" | 119 return "ok" |
119 | 120 |
120 @app.route('/stopAll', methods=['POST']) | 121 @app.route('/stopAll', methods=['POST']) |
121 def stopAll(self, request): | 122 def stopAll(self, request): |
122 self.sfx.stopAll() | 123 self.sfx.stopAll() |