_speaker.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. def speaker_start(frequency: float, volume: float) -> bool:
  2. '''
  3. Output a steady tone of a defined frequency and volume on the Flipper's speaker.
  4. This is a non-blocking operation. The tone will continue until you call :func:`speaker_stop`.
  5. The ``volume`` parameter accepts values from 0.0 (silent) up to 1.0 (very loud).
  6. :param frequency: The frequency to play in `hertz <https://en.wikipedia.org/wiki/Hertz>`_.
  7. :param volume: The volume to use.
  8. :returns: :const:`True` if the speaker was acquired.
  9. .. code-block::
  10. import flipperzero as f0
  11. f0.speaker_start(50.0, 0.8)
  12. '''
  13. pass
  14. def speaker_set_volume(volume: float) -> bool:
  15. '''
  16. Set the speaker's volume while playing a tone. This is a non-blocking operation.
  17. The tone will continue until you call :func:`speaker_stop`.
  18. The ``volume`` parameter accepts values from 0.0 (silent) up to 1.0 (very loud).
  19. :param volume: The volume to use.
  20. :returns: :const:`True` if the speaker was acquired.
  21. This function can be used to play `nice` sounds:
  22. .. code-block::
  23. import time
  24. import flipperzero as f0
  25. volume = 0.8
  26. f0.speaker_start(100.0, volume)
  27. for _ in range(0, 150):
  28. volume *= 0.9945679
  29. f0.speaker_set_volume(volume)
  30. time.sleep_ms(1)
  31. f0.speaker_stop()
  32. '''
  33. pass
  34. def speaker_stop() -> bool:
  35. '''
  36. Stop the speaker output.
  37. :returns: :const:`True` if the speaker was successfully released.
  38. '''
  39. pass