|
50 | 50 | import board |
51 | 51 | from micropython import const |
52 | 52 | import digitalio |
53 | | - |
54 | | -try: |
55 | | - import audiocore |
56 | | -except ImportError: |
57 | | - import audioio as audiocore |
58 | 53 | from adafruit_bitmap_font import bitmap_font |
59 | 54 | import displayio |
60 | 55 | from adafruit_display_shapes.rect import Rect |
61 | 56 | from adafruit_display_text import label |
62 | 57 | import terminalio |
63 | 58 | import adafruit_miniqr |
64 | 59 |
|
| 60 | +AUDIO_ENABLED = False |
| 61 | +try: |
| 62 | + import audiocore |
| 63 | + |
| 64 | + AUDIO_ENABLED = True |
| 65 | +except ImportError: |
| 66 | + try: |
| 67 | + import audioio as audiocore |
| 68 | + |
| 69 | + AUDIO_ENABLED = True |
| 70 | + except ImportError: |
| 71 | + # Allow to work with no audio |
| 72 | + pass |
65 | 73 | __version__ = "0.0.0-auto.0" |
66 | 74 | __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_PyBadger.git" |
67 | 75 |
|
@@ -685,11 +693,17 @@ def _sine_sample(length): |
685 | 693 | yield int(tone_volume * math.sin(2 * math.pi * (i / length)) + shift) |
686 | 694 |
|
687 | 695 | def _generate_sample(self, length=100): |
688 | | - if self._sample is not None: |
689 | | - return |
690 | | - self._sine_wave = array.array("H", PyBadgerBase._sine_sample(length)) |
691 | | - self._sample = self._audio_out(board.SPEAKER) # pylint: disable=not-callable |
692 | | - self._sine_wave_sample = audiocore.RawSample(self._sine_wave) |
| 696 | + if AUDIO_ENABLED: |
| 697 | + if self._sample is not None: |
| 698 | + return |
| 699 | + self._sine_wave = array.array("H", PyBadgerBase._sine_sample(length)) |
| 700 | + # pylint: disable=not-callable |
| 701 | + self._sample = self._audio_out( |
| 702 | + board.SPEAKER |
| 703 | + ) # pylint: disable=not-callable |
| 704 | + self._sine_wave_sample = audiocore.RawSample(self._sine_wave) |
| 705 | + else: |
| 706 | + print("Required audio modules were missing") |
693 | 707 |
|
694 | 708 | def _enable_speaker(self, enable): |
695 | 709 | if not hasattr(board, "SPEAKER_ENABLE"): |
|
0 commit comments