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


Python alsaaudio.ALSAAudioError方法代码示例

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


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

示例1: acquire

# 需要导入模块: import alsaaudio [as 别名]
# 或者: from alsaaudio import ALSAAudioError [as 别名]
def acquire(self):
        if self._session.is_active():
            try:
                pcm_args = {
                    'type': alsa.PCM_PLAYBACK,
                    'mode': alsa.PCM_NORMAL,
                }
                if self._args.playback_device != 'default':
                    pcm_args['device'] = self._args.playback_device
                else:
                    pcm_args['card'] = self._args.device
                pcm = alsa.PCM(**pcm_args)

                pcm.setchannels(CHANNELS)
                pcm.setrate(RATE)
                pcm.setperiodsize(PERIODSIZE)
                pcm.setformat(alsa.PCM_FORMAT_S16_LE)

                self._device = pcm
                print "AlsaSink: device acquired"
            except alsa.ALSAAudioError as error:
                print "Unable to acquire device: ", error
                self.release() 
开发者ID:Fornoth,项目名称:spotify-connect-web,代码行数:25,代码来源:console_callbacks.py

示例2: _get_mixer

# 需要导入模块: import alsaaudio [as 别名]
# 或者: from alsaaudio import ALSAAudioError [as 别名]
def _get_mixer():
        try:
            mixer = alsaaudio.Mixer()
        except alsaaudio.ALSAAudioError:
            # no master, we are on a Rpi
            mixer = alsaaudio.Mixer("PCM")
        return mixer 
开发者ID:Sispheor,项目名称:piclodio3,代码行数:9,代码来源:sound_manager.py

示例3: write

# 需要导入模块: import alsaaudio [as 别名]
# 或者: from alsaaudio import ALSAAudioError [as 别名]
def write(self, data):
        if self._session.is_active() and self._device is not None:
            # write is asynchronous, so, we are in race with releasing the device
            self._lock.acquire()
            try:
                if self._device is not None:
                    self._device.write(data)
            except alsa.ALSAAudioError as error:
                print "Ups! Some badness happened: ", error
            finally:
                self._lock.release() 
开发者ID:Fornoth,项目名称:spotify-connect-web,代码行数:13,代码来源:console_callbacks.py

示例4: __init__

# 需要导入模块: import alsaaudio [as 别名]
# 或者: from alsaaudio import ALSAAudioError [as 别名]
def __init__(self, config):
        super().__init__()
        self.config = config
        self.cardindex = self.config["alsamixer"]["card"]
        self.control = self.config["alsamixer"]["control"]
        self.min_volume = self.config["alsamixer"]["min_volume"]
        self.max_volume = self.config["alsamixer"]["max_volume"]
        self.volume_scale = self.config["alsamixer"]["volume_scale"]

        known_cards = alsaaudio.cards()
        try:
            known_controls = alsaaudio.mixers(self.cardindex)
        except alsaaudio.ALSAAudioError:
            raise exceptions.MixerError(
                f"Could not find ALSA soundcard with index {self.cardindex:d}. "
                "Known soundcards include: "
                ", ".join(known_cards)
            )

        if self.control not in known_controls:
            raise exceptions.MixerError(
                f"Could not find ALSA mixer control {self.control} on "
                f"card {self.cardindex:d}. "
                f"Known mixers on card {self.cardindex:d} include: "
                ", ".join(known_controls)
            )

        self._last_volume = None
        self._last_mute = None

        logger.info(
            f"Mixing using ALSA, card {self.cardindex:d}, "
            f"mixer control {self.control!r}."
        ) 
开发者ID:mopidy,项目名称:mopidy-alsamixer,代码行数:36,代码来源:mixer.py

示例5: get_mute

# 需要导入模块: import alsaaudio [as 别名]
# 或者: from alsaaudio import ALSAAudioError [as 别名]
def get_mute(self):
        try:
            channels_muted = self._mixer.getmute()
        except alsaaudio.ALSAAudioError as exc:
            logger.debug(f"Getting mute state failed: {exc}")
            return None
        if all(channels_muted):
            return True
        elif not any(channels_muted):
            return False
        else:
            # Not all channels have the same mute state
            return None 
开发者ID:mopidy,项目名称:mopidy-alsamixer,代码行数:15,代码来源:mixer.py

示例6: set_mute

# 需要导入模块: import alsaaudio [as 别名]
# 或者: from alsaaudio import ALSAAudioError [as 别名]
def set_mute(self, mute):
        try:
            self._mixer.setmute(int(mute))
            return True
        except alsaaudio.ALSAAudioError as exc:
            logger.debug(f"Setting mute state failed: {exc}")
            return False 
开发者ID:mopidy,项目名称:mopidy-alsamixer,代码行数:9,代码来源:mixer.py

示例7: test_fails_if_card_is_unknown

# 需要导入模块: import alsaaudio [as 别名]
# 或者: from alsaaudio import ALSAAudioError [as 别名]
def test_fails_if_card_is_unknown(self, alsa_mock):
        alsa_mock.cards.return_value = ["PCH", "SB"]
        alsa_mock.mixers.side_effect = alsa_mock.ALSAAudioError(
            "No such file or directory [hw:2]"
        )
        config = {"alsamixer": {"card": 2, "control": "Master"}}

        with self.assertRaises(exceptions.MixerError):
            self.get_mixer(config=config)

        alsa_mock.mixers.assert_called_once_with(2) 
开发者ID:mopidy,项目名称:mopidy-alsamixer,代码行数:13,代码来源:test_mixer.py

示例8: test_get_mute_when_unsupported

# 需要导入模块: import alsaaudio [as 别名]
# 或者: from alsaaudio import ALSAAudioError [as 别名]
def test_get_mute_when_unsupported(self, alsa_mock):
        alsa_mock.ALSAAudioError = alsaaudio.ALSAAudioError
        mixer = self.get_mixer(alsa_mock)
        mixer_mock = alsa_mock.Mixer.return_value
        mixer_mock.getmute.side_effect = alsa_mock.ALSAAudioError

        self.assertIsNone(mixer.get_mute())

        mixer_mock.getmute.assert_called_once_with() 
开发者ID:mopidy,项目名称:mopidy-alsamixer,代码行数:11,代码来源:test_mixer.py

示例9: __test_device

# 需要导入模块: import alsaaudio [as 别名]
# 或者: from alsaaudio import ALSAAudioError [as 别名]
def __test_device(device, record):
        """
            Test selected ALSA device, making sure it handles both stereo and
            mono and both 44.1KHz and 22.05KHz on output, mono and 16 kHz on
            input.

            On a typical RPI configuration, default with hifiberry card is not
            configured to do software-mono, so we'll use
            plughw:CARD=sndrpihifiberry instead.
            Likewise, on 2019 cards, hw:CARD=seeed2micvoicec is not able to run
            mono sound.

            @param device: name of the sound device
            @type device: six.text_type
            @param record: C{True} if this method is looking for recording
            device. C{False} if the device should only playback.
            @type record: bool
        """
        try:
            dev = None

            if record:
                dev = alsaaudio.PCM(alsaaudio.PCM_CAPTURE, device=device)
            else:
                dev = alsaaudio.PCM(device=device)

            if (
                dev.setformat(alsaaudio.PCM_FORMAT_S16_LE)
                != alsaaudio.PCM_FORMAT_S16_LE
            ):
                return False
            if record:
                if dev.setchannels(1) != 1:
                    return False
                if dev.setrate(16000) != 16000:
                    return False
            else:
                if dev.setchannels(2) != 2:
                    return False
                if dev.setchannels(1) != 1:
                    return False
                if dev.setrate(44100) != 44100:
                    return False
                if dev.setrate(22050) != 22050:
                    return False
        except alsaaudio.ALSAAudioError:
            return False
        finally:
            if dev:
                dev.close()
        return True 
开发者ID:nabaztag2018,项目名称:pynab,代码行数:53,代码来源:sound_alsa.py


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