本文整理汇总了Python中alsaaudio.Mixer.getvolume方法的典型用法代码示例。如果您正苦于以下问题:Python Mixer.getvolume方法的具体用法?Python Mixer.getvolume怎么用?Python Mixer.getvolume使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类alsaaudio.Mixer
的用法示例。
在下文中一共展示了Mixer.getvolume方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: set_volume
# 需要导入模块: from alsaaudio import Mixer [as 别名]
# 或者: from alsaaudio.Mixer import getvolume [as 别名]
def set_volume(request, username, value):
global volume_who, volume_direction
m = Mixer()
if value > m.getvolume()[0]:
volume_direction = "up"
volume_who = username
elif value < m.getvolume()[0]:
volume_direction = "down"
else:
return volume() # no change, quit
volume_who = username
m.setvolume(value)
return volume()
示例2: process
# 需要导入模块: from alsaaudio import Mixer [as 别名]
# 或者: from alsaaudio.Mixer import getvolume [as 别名]
def process(self, data):
self.client.emit(Message(data))
if "mycroft.stop" in data:
self.client.emit(Message("mycroft.stop"))
if "volume.up" in data:
self.client.emit(
Message("IncreaseVolumeIntent", metadata={'play_sound': True}))
if "volume.down" in data:
self.client.emit(
Message("DecreaseVolumeIntent", metadata={'play_sound': True}))
if "system.test.begin" in data:
self.client.emit(Message('recognizer_loop:sleep'))
if "system.test.end" in data:
self.client.emit(Message('recognizer_loop:wake_up'))
if "mic.test" in data:
mixer = Mixer()
prev_vol = mixer.getvolume()[0]
mixer.setvolume(35)
self.client.emit(Message("speak", metadata={
'utterance': "I am testing one two three"}))
time.sleep(0.5) # Prevents recording the loud button press
record("/tmp/test.wav", 3.0)
mixer.setvolume(prev_vol)
play_wav("/tmp/test.wav")
time.sleep(3.5) # Pause between tests so it's not so fast
# Test audio muting on arduino
subprocess.call('speaker-test -P 10 -l 0 -s 1', shell=True)
示例3: process
# 需要导入模块: from alsaaudio import Mixer [as 别名]
# 或者: from alsaaudio.Mixer import getvolume [as 别名]
def process(self, data):
self.client.emit(Message(data))
if "mycroft.stop" in data:
self.client.emit(Message("mycroft.stop"))
if "volume.up" in data:
self.client.emit(
Message("IncreaseVolumeIntent", metadata={'play_sound': True}))
if "volume.down" in data:
self.client.emit(
Message("DecreaseVolumeIntent", metadata={'play_sound': True}))
if "system.test.begin" in data:
self.client.emit(Message('recognizer_loop:sleep'))
if "system.test.end" in data:
self.client.emit(Message('recognizer_loop:wake_up'))
if "mic.test" in data:
mixer = Mixer()
prev_vol = mixer.getvolume()[0]
mixer.setvolume(35)
self.client.emit(Message("speak", metadata={
'utterance': "I am testing one two three"}))
record("/tmp/test.wav", 3.5)
play_wav("/tmp/test.wav")
# Test audio muting on arduino
self.client.emit(Message("speak", metadata={
'utterance': "LOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOONG"}))
mixer.setvolume(prev_vol)
示例4: process
# 需要导入模块: from alsaaudio import Mixer [as 别名]
# 或者: from alsaaudio.Mixer import getvolume [as 别名]
def process(self, data):
self.client.emit(Message(data))
if "mycroft.stop" in data:
self.client.emit(Message("mycroft.stop"))
if "volume.up" in data:
self.client.emit(
Message("IncreaseVolumeIntent", metadata={'play_sound': True}))
if "volume.down" in data:
self.client.emit(
Message("DecreaseVolumeIntent", metadata={'play_sound': True}))
if "system.test.begin" in data:
self.client.emit(Message('recognizer_loop:sleep'))
if "system.test.end" in data:
self.client.emit(Message('recognizer_loop:wake_up'))
if "mic.test" in data:
mixer = Mixer()
prev_vol = mixer.getvolume()[0]
mixer.setvolume(35)
self.client.emit(Message("speak", metadata={
'utterance': "I am testing one two three"}))
time.sleep(0.5) # Prevents recording the loud button press
record("/tmp/test.wav", 3.0)
mixer.setvolume(prev_vol)
play_wav("/tmp/test.wav")
time.sleep(3.5) # Pause between tests so it's not so fast
# Test audio muting on arduino
subprocess.call('speaker-test -P 10 -l 0 -s 1', shell=True)
if "unit.shutdown" in data:
self.client.emit(
Message("enclosure.eyes.timedspin",
metadata={'length': 12000}))
self.client.emit(Message("enclosure.mouth.reset"))
subprocess.call('systemctl poweroff -i', shell=True)
if "unit.reboot" in data:
self.client.emit(
Message("enclosure.eyes.spin"))
self.client.emit(Message("enclosure.mouth.reset"))
subprocess.call('systemctl reboot -i', shell=True)
if "unit.setwifi" in data:
self.client.emit(Message("wifisetup.start"))
if "unit.factory-reset" in data:
subprocess.call(
'rm ~/.mycroft/identity/identity.json',
shell=True)
self.client.emit(
Message("enclosure.eyes.spin"))
self.client.emit(Message("enclosure.mouth.reset"))
subprocess.call('systemctl reboot -i', shell=True)
示例5: __update_volume
# 需要导入模块: from alsaaudio import Mixer [as 别名]
# 或者: from alsaaudio.Mixer import getvolume [as 别名]
def __update_volume(self, level=0):
mixer = Mixer()
volume = mixer.getvolume()[0]
code = self.get_volume_code(volume) + level
code = self.fix_code(code)
if code in self.VOLUMES:
volume = self.VOLUMES[code]
mixer.setvolume(volume)
return code, volume
示例6: click
# 需要导入模块: from alsaaudio import Mixer [as 别名]
# 或者: from alsaaudio.Mixer import getvolume [as 别名]
def click(self, button):
if button == 1:
mixer = Mixer(self.mutedev)
mixer.setmute(not bool(mixer.getmute()[0]))
elif button == 4:
mixer = Mixer(self.voldev)
try:
mixer.setvolume(mixer.getvolume()[0] + self.step)
except ALSAAudioError:
return
elif button == 5:
mixer = Mixer(self.voldev)
try:
mixer.setvolume(mixer.getvolume()[0] - self.step)
except ALSAAudioError:
return
self.update()
示例7: __update_volume
# 需要导入模块: from alsaaudio import Mixer [as 别名]
# 或者: from alsaaudio.Mixer import getvolume [as 别名]
def __update_volume(self, change=0):
"""
Tries to change volume level
:param change: +1 or -1; the step to change by
:return: new code (0..11), whether volume changed
"""
mixer = Mixer()
old_level = self.volume_to_level(mixer.getvolume()[0])
new_level = self.bound_level(old_level + change)
self.enclosure.eyes_volume(new_level)
mixer.setvolume(self.level_to_volume(new_level))
return new_level, new_level != old_level
示例8: __update_volume
# 需要导入模块: from alsaaudio import Mixer [as 别名]
# 或者: from alsaaudio.Mixer import getvolume [as 别名]
def __update_volume(self, level=0):
"""
Tries to change volume level
:param level: +1 or -1; the step to change by
:return: new code (0..11), whether volume changed
"""
mixer = Mixer()
volume = mixer.getvolume()[0]
old_code = self.get_volume_code(volume)
new_code = self.fix_code(old_code + level)
if new_code in self.VOLUMES:
volume = self.VOLUMES[new_code]
mixer.setvolume(volume)
return new_code, new_code != old_code
示例9: __init__
# 需要导入模块: from alsaaudio import Mixer [as 别名]
# 或者: from alsaaudio.Mixer import getvolume [as 别名]
class RaspberryGPIOPlugin:
buttons = {
12: "volume_up",
11: "volume_down",
8: "skip",
10: "play_pause",
}
def __init__(self, player):
self.player = player
self._alsa_mixer = Mixer(control="PCM")
self.is_pressed = False
GPIO.setmode(GPIO.BOARD)
input_buttons = [k for k in self.buttons.keys()]
GPIO.setup(input_buttons, GPIO.IN, pull_up_down=GPIO.PUD_UP)
def __call__(self):
for port_number, callback_name in self.buttons.items():
if GPIO.input(port_number) == 0:
getattr(self, callback_name)()
return
else:
self.is_pressed = False
def _change_volume(self, change):
new_volume = self.current_volume + change
self._alsa_mixer.setvolume(new_volume)
@property
def current_volume(self):
return self._alsa_mixer.getvolume()[0]
@debounced
def skip(self):
self.player.skip()
@debounced
def play_pause(self):
self.player.play_pause()
def volume_up(self):
self._change_volume(1)
def volume_down(self):
self._change_volume(-1)
示例10: notify
# 需要导入模块: from alsaaudio import Mixer [as 别名]
# 或者: from alsaaudio.Mixer import getvolume [as 别名]
def notify(self, timestamp):
with self.LOCK:
if self.data.__contains__(timestamp):
volume = None
self.alarm_on = True
delay = self.__calculate_delay(self.max_delay)
while self.alarm_on and datetime.now() < delay:
play_mp3(self.file_path).communicate()
self.speak_dialog('alarm.stop')
time.sleep(self.repeat_time + 2)
if not volume and datetime.now() >= delay:
mixer = Mixer()
volume = mixer.getvolume()[0]
mixer.setvolume(100)
delay = self.__calculate_delay(self.extended_delay)
if volume:
Mixer().setvolume(volume)
self.remove(timestamp)
self.alarm_on = False
self.save()
示例11: notify
# 需要导入模块: from alsaaudio import Mixer [as 别名]
# 或者: from alsaaudio.Mixer import getvolume [as 别名]
def notify(self, timestamp):
with self.LOCK:
if self.data.__contains__(timestamp):
volume = None
self.reminder_on = True
delay = self.__calculate_delay(self.max_delay)
while self.reminder_on and datetime.now() < delay:
self.speak_dialog(
'reminder.notify',
data=self.build_feedback_payload(timestamp))
time.sleep(1)
self.speak_dialog('reminder.stop')
time.sleep(self.repeat_time)
if not volume and datetime.now() >= delay:
mixer = Mixer()
volume = mixer.getvolume()[0]
mixer.setvolume(100)
delay = self.__calculate_delay(self.extended_delay)
if volume:
Mixer().setvolume(volume)
self.remove(timestamp)
self.reminder_on = False
self.save()
示例12: Mixer
# 需要导入模块: from alsaaudio import Mixer [as 别名]
# 或者: from alsaaudio.Mixer import getvolume [as 别名]
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# [email protected]
import sys
from alsaaudio import Mixer
m = Mixer()
if __name__ == '__main__':
output = ["{} {}".format(u'\uf001', m.getvolume()[0])]
color = False
if m.getmute()[0]:
color = '#666666'
output += output
if color:
output.append(color)
print('\n'.join(output))
示例13: handle_set_volume
# 需要导入模块: from alsaaudio import Mixer [as 别名]
# 或者: from alsaaudio.Mixer import getvolume [as 别名]
def handle_set_volume(self, message):
mixer = Mixer()
code, volume = self.get_volume(message, mixer.getvolume()[0])
mixer.setvolume(volume)
self.speak_dialog('set.volume', data={'volume': code})
示例14: process
# 需要导入模块: from alsaaudio import Mixer [as 别名]
# 或者: from alsaaudio.Mixer import getvolume [as 别名]
def process(self, data):
self.ws.emit(Message(data))
if "Command: system.version" in data:
self.ws.emit(Message("enclosure.start"))
if "mycroft.stop" in data:
create_signal('buttonPress') # FIXME - Must use WS instead
self.ws.emit(Message("mycroft.stop"))
if "volume.up" in data:
self.ws.emit(
Message("IncreaseVolumeIntent", {'play_sound': True}))
if "volume.down" in data:
self.ws.emit(
Message("DecreaseVolumeIntent", {'play_sound': True}))
if "system.test.begin" in data:
self.ws.emit(Message('recognizer_loop:sleep'))
if "system.test.end" in data:
self.ws.emit(Message('recognizer_loop:wake_up'))
if "mic.test" in data:
mixer = Mixer()
prev_vol = mixer.getvolume()[0]
mixer.setvolume(35)
self.ws.emit(Message("speak", {
'utterance': "I am testing one two three"}))
time.sleep(0.5) # Prevents recording the loud button press
record("/tmp/test.wav", 3.0)
mixer.setvolume(prev_vol)
play_wav("/tmp/test.wav").communicate()
# Test audio muting on arduino
subprocess.call('speaker-test -P 10 -l 0 -s 1', shell=True)
if "unit.shutdown" in data:
self.ws.emit(
Message("enclosure.eyes.timedspin",
{'length': 12000}))
self.ws.emit(Message("enclosure.mouth.reset"))
subprocess.call('systemctl poweroff -i', shell=True)
if "unit.reboot" in data:
self.ws.emit(
Message("enclosure.eyes.spin"))
self.ws.emit(Message("enclosure.mouth.reset"))
subprocess.call('systemctl reboot -i', shell=True)
if "unit.setwifi" in data:
self.ws.emit(Message("mycroft.wifi.start"))
if "unit.factory-reset" in data:
subprocess.call(
'rm ~/.mycroft/identity/identity2.json',
shell=True)
self.ws.emit(
Message("enclosure.eyes.spin"))
self.ws.emit(Message("enclosure.mouth.reset"))
subprocess.call('systemctl reboot -i', shell=True)
示例15: Harold
# 需要导入模块: from alsaaudio import Mixer [as 别名]
# 或者: from alsaaudio.Mixer import getvolume [as 别名]
class Harold(object):
def __init__(self, mplfifo, ser, mpout, beep=True):
self.playing = False
self.mixer = Mixer(control='PCM')
self.fifo = mplfifo
self.ser = ser
self.mpout = mpout
self.beep = beep
def write(self, *args, **kwargs):
delay = kwargs.pop("delay", 0.5)
kws = {"file": self.fifo}
kws.update(kwargs)
print(*args, **kws)
time.sleep(delay)
def __call__(self):
if not self.playing:
userlog = open("/home/pi/logs/user_log.csv", "a")
# Lower the volume during quiet hours... Don't piss off the RA!
self.mixer.setvolume(85 if quiet_hours() else 100)
varID = self.ser.readline()
print(varID)
# mplayer will play any files sent to the FIFO file.
if self.beep:
self.write("loadfile", DING_SONG)
if "ready" not in varID:
# Turn the LEDs off
LED.on(False)
print("Turning off LEDs")
# Get the username from the ibutton
print("Getting User Data")
uid, homedir = read_ibutton(varID)
# Print the user's name (Super handy for debugging...)
print("User: '" + uid + "'\n")
song = get_user_song(homedir, uid)
print("Now playing '" + song + "'...\n")
varID = varID[:-2]
userlog.write("\n" + time.strftime('%Y/%m/%d %H:%M:%S') + "," + uid + "," + song)
self.write("loadfile '" + song.replace("'", "\\'") + "'\nget_time_length",
delay=0.0)
line = self.mpout.readline().strip()
# timeout = time.time() + 5 # Five second time out to wait for song time.
while not line.startswith("ANS_LENGTH="):
line = self.mpout.readline().strip()
if line.startswith("Playing"): # Check if mplayer can play file.
if self.mpout.readline().strip() == "":
self.starttime = time.time()
self.endtime = time.time()
self.playing = True
break
elif line.startswith("ANS_LENGTH="):
duration = float(line.strip().split("=")[-1])
self.starttime = time.time()
self.endtime = time.time() + min(30, duration)
self.playing = True
else:
pass
userlog.close()
elif time.time() >= self.endtime:
self.write("stop")
self.playing = False
self.ser.flushInput()
LED.on(True)
print("Stopped\n")
elif time.time() >= self.starttime+28:
# Fade out the music at the end.
vol = int(self.mixer.getvolume()[0])
while vol > 60:
vol -= 1 + (100 - vol)/30.
self.mixer.setvolume(int(vol))
time.sleep(0.1)