def get_current_volume(self):
cmd = ShellCmd(self.base_get_cmd)
while not cmd.is_done() and not rospy.is_shutdown():
rospy.sleep(0.1)
output = cmd.get_stdout()
rospy.logdebug("self.base_get_cmd output: " + str(output))
# Output looks like:
# Simple mixer control 'Master',0
# Capabilities: pvolume pvolume-joined pswitch pswitch-joined
# Playback channels: Mono
# Limits: Playback 0 - 87
# Mono: Playback 44 [51%] [-32.25dB] [on]
pct_idx = output.index('%')
# At most 3 characters of 100%
pct_text = output[pct_idx - 3:pct_idx]
# Remove [ if it was less than 3 chars
pct_text = pct_text.replace('[', '')
# Remove spaces if it was less than 2 char
pct_text = pct_text.strip()
curr_vol = int(pct_text)
return curr_vol
评论列表
文章目录