mirror of
https://github.com/pybricks/pybricks-api.git
synced 2026-09-12 01:24:17 +00:00
api/builtins: Update speaker API
- Volume is a setting. - Remove beeps method. To do multiple beeps, users can make their own loop. - Rename file to play.
This commit is contained in:
+10
-18
@@ -53,42 +53,34 @@
|
||||
|
||||
.. rubric:: Using the speaker
|
||||
|
||||
.. automethod:: pybricks._instances.speaker.volume
|
||||
|
||||
.. automethod:: pybricks._instances.speaker.beep
|
||||
|
||||
Example::
|
||||
|
||||
# Initialize EV3 at the top of your script
|
||||
brick = EV3Brick()
|
||||
ev3 = EV3Brick()
|
||||
|
||||
# A simple beep
|
||||
brick.speaker.beep()
|
||||
ev3.speaker.beep()
|
||||
|
||||
# A high pitch (1500 Hz) for one second (1000 ms) at 50% volume
|
||||
brick.speaker.beep(1500, 1000, 50)
|
||||
# A high pitch (1500 Hz) for one second (1000 ms)
|
||||
ev3.speaker.beep(1500, 1000)
|
||||
|
||||
|
||||
.. automethod:: pybricks._instances.speaker.beeps
|
||||
.. automethod:: pybricks._instances.speaker.play
|
||||
|
||||
Example::
|
||||
|
||||
# Initialize EV3 at the top of your script
|
||||
brick = EV3Brick()
|
||||
|
||||
# Make 5 simple beeps
|
||||
brick.speaker.beeps(5)
|
||||
|
||||
.. automethod:: pybricks._instances.speaker.file
|
||||
|
||||
Example::
|
||||
|
||||
# Initialize EV3 at the top of your script
|
||||
brick = EV3Brick()
|
||||
ev3 = EV3Brick()
|
||||
|
||||
# Play one of the built-in sounds
|
||||
brick.speaker.file(SoundFile.HELLO)
|
||||
ev3.speaker.play(SoundFile.HELLO)
|
||||
|
||||
# Play a sound file from your project folder
|
||||
brick.speaker.file('mysound.wav')
|
||||
ev3.speaker.play('mysound.wav')
|
||||
|
||||
.. rubric:: Using the screen
|
||||
|
||||
|
||||
+11
-15
@@ -359,35 +359,31 @@ class Display():
|
||||
|
||||
|
||||
class Speaker():
|
||||
"""Play beeps and sound files using a speaker."""
|
||||
"""Play beeps and sounds using a speaker."""
|
||||
|
||||
def beep(self, frequency=500, duration=100, volume=30):
|
||||
def volume(self, volume):
|
||||
"""Set the speaker volume.
|
||||
|
||||
Arguments:
|
||||
volume (:ref:`percentage`): Volume of the speaker.
|
||||
"""
|
||||
pass
|
||||
|
||||
def beep(self, frequency=500, duration=100):
|
||||
"""Play a beep/tone.
|
||||
|
||||
Arguments:
|
||||
frequency (:ref:`frequency`): Frequency of the beep
|
||||
(*Default*: 500).
|
||||
duration (:ref:`time`): Duration of the beep (*Default*: 100).
|
||||
volume (:ref:`percentage`): Volume of the beep (*Default*: 30).
|
||||
"""
|
||||
pass
|
||||
|
||||
def beeps(self, number):
|
||||
"""Play a number of default beeps with a brief pause in between.
|
||||
|
||||
Arguments:
|
||||
number (int): Number of beeps.
|
||||
|
||||
"""
|
||||
pass
|
||||
|
||||
def file(self, file_name, volume=100):
|
||||
def play(self, file_name):
|
||||
"""Play a sound file.
|
||||
|
||||
Arguments:
|
||||
file_name (str): Path to the sound file, including extension.
|
||||
volume (:ref:`percentage`): Volume of the sound (*Default*: 100).
|
||||
|
||||
"""
|
||||
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user