当前位置: 首页>>代码示例>>Python>>正文


Python Mixer.setvolume方法代码示例

本文整理汇总了Python中alsaaudio.Mixer.setvolume方法的典型用法代码示例。如果您正苦于以下问题:Python Mixer.setvolume方法的具体用法?Python Mixer.setvolume怎么用?Python Mixer.setvolume使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在alsaaudio.Mixer的用法示例。


在下文中一共展示了Mixer.setvolume方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: process

# 需要导入模块: from alsaaudio import Mixer [as 别名]
# 或者: from alsaaudio.Mixer import setvolume [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)
开发者ID:kagesenshi,项目名称:mycroft-core,代码行数:36,代码来源:enclosure.py

示例2: process

# 需要导入模块: from alsaaudio import Mixer [as 别名]
# 或者: from alsaaudio.Mixer import setvolume [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)
开发者ID:branux,项目名称:mycroft-core,代码行数:37,代码来源:enclosure.py

示例3: process

# 需要导入模块: from alsaaudio import Mixer [as 别名]
# 或者: from alsaaudio.Mixer import setvolume [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)
开发者ID:bisaysavath,项目名称:mycroft-core,代码行数:62,代码来源:enclosure.py

示例4: __update_volume

# 需要导入模块: from alsaaudio import Mixer [as 别名]
# 或者: from alsaaudio.Mixer import setvolume [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
开发者ID:Acidburn0zzz,项目名称:mycroft-core,代码行数:11,代码来源:__init__.py

示例5: __update_volume

# 需要导入模块: from alsaaudio import Mixer [as 别名]
# 或者: from alsaaudio.Mixer import setvolume [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
开发者ID:forslund,项目名称:mycroft-core,代码行数:14,代码来源:__init__.py

示例6: set_volume

# 需要导入模块: from alsaaudio import Mixer [as 别名]
# 或者: from alsaaudio.Mixer import setvolume [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()
开发者ID:Ferada,项目名称:nih,代码行数:16,代码来源:volume.py

示例7: __update_volume

# 需要导入模块: from alsaaudio import Mixer [as 别名]
# 或者: from alsaaudio.Mixer import setvolume [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
开发者ID:branux,项目名称:mycroft-core,代码行数:17,代码来源:__init__.py

示例8: __init__

# 需要导入模块: from alsaaudio import Mixer [as 别名]
# 或者: from alsaaudio.Mixer import setvolume [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)
开发者ID:SpotiQue,项目名称:Core,代码行数:48,代码来源:raspberry_gpio.py

示例9: click

# 需要导入模块: from alsaaudio import Mixer [as 别名]
# 或者: from alsaaudio.Mixer import setvolume [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()
开发者ID:tom5760,项目名称:wipi,代码行数:22,代码来源:volume.py

示例10: notify

# 需要导入模块: from alsaaudio import Mixer [as 别名]
# 或者: from alsaaudio.Mixer import setvolume [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()
开发者ID:forslund,项目名称:mycroft-core,代码行数:23,代码来源:__init__.py

示例11: notify

# 需要导入模块: from alsaaudio import Mixer [as 别名]
# 或者: from alsaaudio.Mixer import setvolume [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()
开发者ID:Alphacodeclub,项目名称:mycroft-core,代码行数:26,代码来源:__init__.py

示例12: ALSA

# 需要导入模块: from alsaaudio import Mixer [as 别名]
# 或者: from alsaaudio.Mixer import setvolume [as 别名]

#.........这里部分代码省略.........

    def run(self):
        self.create_mixer()

        muted = False
        if self.has_mute:
            muted = self.alsamixer.getmute()[self.channel] == 1

        self.fdict["volume"] = self.get_cur_volume()
        self.fdict["muted"] = self.muted if muted else self.unmuted
        self.fdict["db"] = self.get_db()

        if muted and self.format_muted is not None:
            output_format = self.format_muted
        else:
            output_format = self.format

        self.data = self.fdict
        self.output = {
            "full_text": output_format.format(**self.fdict),
            "color": self.color_muted if muted else self.color,
        }

    def switch_mute(self):
        if self.has_mute:
            muted = self.alsamixer.getmute()[self.channel]
            self.alsamixer.setmute(not muted)

    def get_cur_volume(self):
        if self.map_volume:
            dbCur = self.get_db() * 100.0
            dbMin = self.dbMin * 100.0
            dbMax = self.dbMax * 100.0

            dbCur_norm = self.exp10((dbCur - dbMax) / 6000.0)
            dbMin_norm = self.exp10((dbMin - dbMax) / 6000.0)

            vol = (dbCur_norm - dbMin_norm) / (1 - dbMin_norm)
            vol = int(round(vol * 100, 0))

            return vol
        else:
            return self.alsamixer.getvolume()[self.channel]

    def get_new_volume(self, direction):
        if direction == "inc":
            volume = (self.fdict["volume"] + 1) / 100
        elif direction == "dec":
            volume = (self.fdict["volume"] - 1) / 100

        dbMin = self.dbMin * 100
        dbMax = self.dbMax * 100

        dbMin_norm = self.exp10((dbMin - dbMax) / 6000.0)

        vol = volume * (1 - dbMin_norm) + dbMin_norm

        if direction == "inc":
            dbNew = min(self.dbMax, ceil(((6000.0 * log10(vol)) + dbMax) / 100))
        elif direction == "dec":
            dbNew = max(self.dbMin, floor(((6000.0 * log10(vol)) + dbMax) / 100))

        volNew = int(round(self.map_db(dbNew, self.dbMin, self.dbMax, 0, 100), 0))

        return volNew

    def increase_volume(self, delta=None):
        if self.map_volume:
            vol = self.get_new_volume("inc")

            self.alsamixer.setvolume(vol)
        else:
            vol = self.alsamixer.getvolume()[self.channel]
            self.alsamixer.setvolume(min(100, vol + (delta if delta else self.increment)))

    def decrease_volume(self, delta=None):
        if self.map_volume:
            vol = self.get_new_volume("dec")

            self.alsamixer.setvolume(vol)
        else:
            vol = self.alsamixer.getvolume()[self.channel]
            self.alsamixer.setvolume(max(0, vol - (delta if delta else self.increment)))

    def get_db(self):
        db = (((self.dbMax - self.dbMin) / 100) * self.alsamixer.getvolume()[self.channel]) + self.dbMin
        db = int(round(db, 0))

        return db

    def map_db(self, value, dbMin, dbMax, volMin, volMax):
        dbRange = dbMax - dbMin
        volRange = volMax - volMin

        volScaled = float(value - dbMin) / float(dbRange)

        return volMin + (volScaled * volRange)

    def exp10(self, x):
        return exp(x * log(10))
开发者ID:Arvedui,项目名称:i3pystatus,代码行数:104,代码来源:alsa.py

示例13: set_volume

# 需要导入模块: from alsaaudio import Mixer [as 别名]
# 或者: from alsaaudio.Mixer import setvolume [as 别名]
def set_volume(val):
	id = alsaaudio.mixers(SOUND_CARD).index(SOUND_MIXER)
	mixer = Mixer(SOUND_MIXER, id, SOUND_CARD)
	mixer.setvolume(val)
开发者ID:Mustard,项目名称:PCRemoteServer,代码行数:6,代码来源:server.py

示例14: ALSA

# 需要导入模块: from alsaaudio import Mixer [as 别名]
# 或者: from alsaaudio.Mixer import setvolume [as 别名]
class ALSA(IntervalModule):
    """
    Shows volume of ALSA mixer. You can also use this for inputs, btw.

    Requires pyalsaaudio

    .. rubric:: Available formatters

    * `{volume}` — the current volume in percent
    * `{muted}` — the value of one of the `muted` or `unmuted` settings
    * `{card}` — the associated soundcard
    * `{mixer}` — the associated ALSA mixer
    """

    interval = 1

    settings = (
        "format",
        ("format_muted", "optional format string to use when muted"),
        ("mixer", "ALSA mixer"),
        ("mixer_id", "ALSA mixer id"),
        ("card", "ALSA sound card"),
        ("increment", "integer percentage of max volume to in/decrement volume on mousewheel"),
        "muted", "unmuted",
        "color_muted", "color",
        "channel"
    )

    muted = "M"
    unmuted = ""
    color_muted = "#AAAAAA"
    color = "#FFFFFF"
    format = "♪: {volume}"
    format_muted = None
    mixer = "Master"
    mixer_id = 0
    card = 0
    channel = 0
    increment = 5

    alsamixer = None
    has_mute = True

    def init(self):
        self.create_mixer()
        try:
            self.alsamixer.getmute()
        except ALSAAudioError:
            self.has_mute = False

        self.fdict = {
            "card": self.alsamixer.cardname(),
            "mixer": self.mixer,
        }

    def create_mixer(self):
        self.alsamixer = Mixer(
            control=self.mixer, id=self.mixer_id, cardindex=self.card)

    def run(self):
        self.create_mixer()

        muted = False
        if self.has_mute:
            muted = self.alsamixer.getmute()[self.channel] == 1

        self.fdict["volume"] = self.alsamixer.getvolume()[self.channel]
        self.fdict["muted"] = self.muted if muted else self.unmuted

        if muted and self.format_muted is not None:
            output_format = self.format_muted
        else:
            output_format = self.format

        self.output = {
            "full_text": output_format.format(**self.fdict),
            "color": self.color_muted if muted else self.color,
        }

    def on_leftclick(self):
        self.on_rightclick()

    def on_rightclick(self):
        if self.has_mute:
            muted = self.alsamixer.getmute()[self.channel]
            self.alsamixer.setmute(not muted)

    def on_upscroll(self):
        vol = self.alsamixer.getvolume()[self.channel]
        self.alsamixer.setvolume(min(100, vol + self.increment))

    def on_downscroll(self):
        vol = self.alsamixer.getvolume()[self.channel]
        self.alsamixer.setvolume(max(0, vol - self.increment))
开发者ID:JoacoIB,项目名称:i3pystatus,代码行数:96,代码来源:alsa.py

示例15: process

# 需要导入模块: from alsaaudio import Mixer [as 别名]
# 或者: from alsaaudio.Mixer import setvolume [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)
开发者ID:forslund,项目名称:mycroft-core,代码行数:65,代码来源:__init__.py


注:本文中的alsaaudio.Mixer.setvolume方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。