Skip to content

Commit

Permalink
SetVolumeIntent and SetVolumePercentIntent (#43)
Browse files Browse the repository at this point in the history
* + Factored output strings into speechout.py
+ added response creators for multilingual output
+ added rebust substitution for outputs
* matched speech_response and audio_response parameters
+ added German utterances
* removed temporary files from create_zip

* clean branch to generate approveable push request

* + Added implementation for SetVolume Intent

* + Added SetVolumePercentIntent

* + Added utterances for SetVolumePercentIntent

* + Added SetVolumePercentIntent to intent schema
* fixed travis warnings

* + Added Volume slot to mock intent in testcases

* fix indentation

* * fixed discreppency between float and int in SetVolume*Intent
* removed unneded srv-reloads
* fixed copy-pased errors in debug outputs

* * fixed travis errors
* unified outputgeneration for SetVolume*Intents
  • Loading branch information
DFranzen authored and declension committed Mar 6, 2018
1 parent 949ed35 commit 8b4e1e2
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 3 deletions.
13 changes: 13 additions & 0 deletions metadata/intents.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@
}
]
},
{
"intent": "SetVolumePercentIntent",
"slots": [
{
"name": "Player",
"type": "PLAYER"
},
{
"name": "Volume",
"type": "AMAZON.NUMBER"
}
]
},
{
"intent": "NowPlayingIntent",
"slots": [
Expand Down
6 changes: 5 additions & 1 deletion metadata/utterances.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ SetVolumeIntent set volume to {Volume}
SetVolumeIntent set volume {Player} to {Volume}
SetVolumeIntent set volume in {Player} to {Volume}
SetVolumeIntent set volume to {Volume} in {Player}
SetVolumeIntent set {Player} to {Volume} percent

SetVolumePercentIntent set volume to {Volume} percent
SetVolumePercentIntent set volume {Player} to {Volume} percent
SetVolumePercentIntent set volume in {Player} to {Volume} percent
SetVolumePercentIntent set volume to {Volume} percent in {Player}

NowPlayingIntent what song is this
NowPlayingIntent what song this is
Expand Down
5 changes: 4 additions & 1 deletion squeezealexa/alexa/intents.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ class General(object):
class Custom(object):
HELP, CANCEL, STOP = ("%sIntent" % s
for s in ["Help", "Cancel", "Stop"])
INC_VOL, DEC_VOL = ("%sVolumeIntent" % s for s in ["Increase", "Decrease"])
INC_VOL, DEC_VOL = ("%sVolumeIntent" % s
for s in ["Increase", "Decrease"])
SET_VOL, SET_VOL_PERCENT = ("%sIntent" % s
for s in ["SetVolume", "SetVolumePercent"])
CURRENT, SELECT_PLAYER = ("%sIntent" % s
for s in ["NowPlaying", "SelectPlayer"])
47 changes: 47 additions & 0 deletions squeezealexa/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,53 @@ def on_current(self, intent, session, pid=None):
heading = None
return self.smart_response(text=heading, speech=desc)

@handler.handle(Custom.SET_VOL)
def on_set_vol(self, intent, session, pid=None):
try:
vol = float(intent['slots']['Volume']['value'])
print_d("Extracted volume slot: %.1f" % vol)
except KeyError:
print_d("Couldn't process volume from: %s" % intent)
desc = "Select a volume value between 0 and 10"
heading = "Invalid volume value"
return self.smart_response(text=heading,
speech=desc)
if (vol > 10) or (vol < 0):
print_d("Volume value out of range: %.1f" % vol)
desc = "Select a volume value between 0 and 10"
heading = "Volume value out of range: %.1f" % vol
return self.smart_response(text=heading,
speech=desc)
self.get_server().set_volume(vol * 10, pid)
desc = "OK"
vol_out = vol if (vol != int(vol)) else int(vol)
heading = "Set volume to %s" % vol_out
return self.smart_response(text=heading,
speech=desc)

@handler.handle(Custom.SET_VOL_PERCENT)
def on_set_vol_percent(self, intent, session, pid=None):
try:
vol = int(float(intent['slots']['Volume']['value']))
print_d("Extracted volume slot: %d" % vol)
except KeyError:
print_d("Couldn't process volume from: %s" % intent)
desc = "Select a volume value between 0 and 100 precent"
heading = "Invalid volume value"
return self.smart_response(text=heading,
speech=desc)
if (vol > 100) or (vol < 0):
print_d("Volume value out of range: %d" % vol)
desc = "Select a volume value between 0 and 100 percent"
heading = "Volume value out of range: %d percent" % vol
return self.smart_response(text=heading,
speech=desc)
self.get_server().set_volume(vol, pid)
desc = "OK"
heading = "Set Volume to %d percent" % vol
return self.smart_response(text=heading,
speech=desc)

@handler.handle(Custom.INC_VOL)
def on_inc_vol(self, intent, session, pid=None):
self.get_server().change_volume(+12.5, player_id=pid)
Expand Down
6 changes: 6 additions & 0 deletions squeezealexa/squeezebox/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,12 @@ def change_volume(self, delta, player_id=None):
cmd = "mixer volume %s%.1f" % ('+' if delta > 0 else '', float(delta))
self.player_request(cmd, player_id=player_id)

def set_volume(self, value, player_id=None):
if not value:
return
cmd = "mixer volume %.1f" % float(value)
self.player_request(cmd, player_id=player_id)

def get_milliseconds(self):
secs = self.player_request("time ?") or 0
return float(secs) * 1000.0
Expand Down
3 changes: 2 additions & 1 deletion tests/alexa_handlers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ def test_handling_all_intents(self):
alexa = SqueezeAlexa(server=server)
for name, func in handler._handlers.items():
intent = {'name': name,
'slots': {'Player': {'name': 'Player', 'value': 'fake'}}}
'slots': {'Player': {'name': 'Player', 'value': 'fake'},
'Volume': {'name': 'Volume', 'value': '5'}}}
output = alexa.handle(self.request_for(intent, SOME_SESSION))
self.validate_response(name, output)

Expand Down

0 comments on commit 8b4e1e2

Please sign in to comment.