當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。