_speaker.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. .. versionadded:: 1.0.0
  10. .. code-block::
  11. import flipperzero as f0
  12. f0.speaker_start(50.0, 0.8)
  13. '''
  14. pass
  15. def speaker_set_volume(volume: float) -> bool:
  16. '''
  17. Set the speaker's volume while playing a tone. This is a non-blocking operation.
  18. The tone will continue until you call :func:`speaker_stop`.
  19. The ``volume`` parameter accepts values from 0.0 (silent) up to 1.0 (very loud).
  20. :param volume: The volume to use.
  21. :returns: :const:`True` if the speaker was acquired.
  22. .. versionadded:: 1.0.0
  23. This function can be used to play `nice` sounds:
  24. .. code-block::
  25. import time
  26. import flipperzero as f0
  27. volume = 0.8
  28. f0.speaker_start(100.0, volume)
  29. for _ in range(0, 150):
  30. volume *= 0.9945679
  31. f0.speaker_set_volume(volume)
  32. time.sleep_ms(1)
  33. f0.speaker_stop()
  34. '''
  35. pass
  36. def speaker_stop() -> bool:
  37. '''
  38. Stop the speaker output.
  39. :returns: :const:`True` if the speaker was successfully released.
  40. .. versionadded:: 1.0.0
  41. '''
  42. pass