pybricks/builtins: update speaker methods

Update Speaker class with newly implemented methods
This commit is contained in:
David Lechner
2020-01-13 20:14:49 -06:00
parent 0398d04af9
commit 9c024e17c4
4 changed files with 125 additions and 29 deletions
+3 -7
View File
@@ -20,10 +20,6 @@
.. rubric:: Using the speaker
.. todo:: The following method is not yet implemented
.. automethod:: pybricks.hubs::EV3Brick.speaker.volume
.. automethod:: pybricks.hubs::EV3Brick.speaker.beep
.. automethod:: pybricks.hubs::EV3Brick.speaker.play_notes
@@ -32,9 +28,9 @@
.. automethod:: pybricks.hubs::EV3Brick.speaker.say
.. todo:: The following method is not yet implemented
.. automethod:: pybricks.hubs::EV3Brick.speaker.set_speech_options
.. automethod:: pybricks.hubs::EV3Brick.speaker.set_voice_settings
.. automethod:: pybricks.hubs::EV3Brick.speaker.set_volume
.. rubric:: Using the screen
@@ -48,7 +44,7 @@
.. automethod:: pybricks.hubs::EV3Brick.screen.set_font
.. automethod:: pybricks.hubs::EV3Brick.screen.show_image
.. automethod:: pybricks.hubs::EV3Brick.screen.draw_image
.. automethod:: pybricks.hubs::EV3Brick.screen.draw_pixel
+2 -2
View File
@@ -157,8 +157,8 @@ Some signals do not have specific units. They range from a minimum (0%) to a
maximum (100%). Specifics type of percentages are :ref:`relative distances
<relativedistance>` or :ref:`brightnesses <brightness>`.
Another example is the sound :meth:`volume <.builtins.Speaker.volume>`, which
ranges from 0% (silent) to 100% (loudest).
Another example is the sound :meth:`set_volume <.builtins.Speaker.set_volume>`,
which ranges from 0% (silent) to 100% (loudest).
.. _brightness:
+119 -19
View File
@@ -326,14 +326,6 @@ class Motor(DCMotor):
class Speaker():
"""Play beeps and sounds using a speaker."""
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.
@@ -389,7 +381,7 @@ class Speaker():
def say(self, text):
"""Say a given text string.
The settings from :meth:`set_voice_settings` will affect the playback.
The options set by :meth:`set_speech_options` can affect the playback.
Arguments:
text (str): What to say.
@@ -397,18 +389,126 @@ class Speaker():
pass
def set_voice_settings(self, language='en', speed=150, variant='m1'):
"""Configure voice settings used by the ``say`` method.
def set_speech_options(self, voice=None, speed=None, pitch=None):
"""Configure speech settings used by the :meth:`say` method.
Any option that is set to ``None`` will not be changed. If an option
is set to an invalid value :meth:`say` will use the default value
instead.
Arguments:
language (str):
- ``'en'`` (English)
- ``'nl'`` (Dutch)
- ``'de'`` (German)
- TODO: Add all available/supported languages
speed (int): Number of words per minute.
variant (str): Voice variant. You can choose female voices
(``'f1'`` to ``'f5'``) or male voices (``'m1'`` to ``'m7'``).
voice (str):
The voice to use. One of the following:
- ``af``: Afrikaans
- ``an``: Aragonese
- ``bg``: Bulgarian
- ``bs``: Bosnian
- ``ca``: Catalan
- ``cs``: Czech
- ``cy``: Welsh
- ``da``: Danish
- ``de``: German
- ``el``: Greek
- ``en``: English (default)
- ``en-gb``: English (United Kingdom)
- ``en-sc``: English (Scottland)
- ``en-uk-north``: English (United Kingdom, Northern)
- ``en-uk-rp``: English (United Kingdom, Received Pronunciation)
- ``en-uk-wmids``: English (United Kingdom, West Midlands)
- ``en-us``: English (United States)
- ``en-wi``: English (West Indies)
- ``eo``: Esperanto
- ``es``: Spanish
- ``es-la``: Spanish (Latin America)
- ``et``: Estonian
- ``fa``: Persian
- ``fa-pin``: Persian
- ``fi``: Finnish
- ``fr-be``: French (Belgium)
- ``fr-fr``: French (France)
- ``ga``: Irish
- ``grc``: Greek
- ``hi``: Hindi
- ``hr``: Croatian
- ``hu``: Hungarian
- ``hy``: Armenian
- ``hy-west``: Armenian (Western)
- ``id``: Indonesian
- ``is``: Icelandic
- ``it``: Italian
- ``jbo``: Lojban
- ``ka``: Georgian
- ``kn``: Kannada
- ``ku``: Kurdish
- ``la``: Latin
- ``lfn``: Lingua Franca Nova
- ``lt``: Lithuanian
- ``lv``: Latvian
- ``mk``: Macedonian
- ``ml``: Malayalam
- ``ms``: Malay
- ``ne``: Nepali
- ``nl``: Dutch
- ``no``: Norwegian
- ``pa``: Punjabi
- ``pl``: Polish
- ``pt-br``: Portuguese (Brazil)
- ``pt-pt``: Portuguese (Portugal)
- ``ro``: Romanian
- ``ru``: Russian
- ``sk``: Slovak
- ``sq``: Albanian
- ``sr``: Serbian
- ``sv``: Swedish
- ``sw``: Swahili
- ``ta``: Tamil
- ``tr``: Turkish
- ``vi``: Vietnamese
- ``vi-hue``: Vietnamese (Huế )
- ``vi-sgn``: Vietnamese (Saigon)
- ``zh``: Mandarin Chinese
- ``zh-yue``: Cantonese Chinese
The following modifiers can optionally be appended to then end
of the voice name:
- ``+f1``: female variant 1
- ``+f2``: female variant 2
- ``+f3``: female variant 3
- ``+f4``: female variant 4
- ``+f5``: female variant 5
- ``+m1``: male variant 1
- ``+m2``: male variant 2
- ``+m3``: male variant 3
- ``+m4``: male variant 4
- ``+m5``: male variant 5
- ``+m6``: male variant 6
- ``+m7``: male variant 7
- ``+croak``: croak
- ``+whisper``: whisper
- ``+whisperf``: female whisper
speed (int):
Number of words per minute.
pitch (int):
Pitch (0 to 99). Higher numbers make the voice higher pitched
and lower numbers make the voice lower pitched.
"""
pass
def set_volume(self, volume, which='_all_'):
"""Set the speaker volume.
Arguments:
volume (:ref:`percentage`):
Volume of the speaker.
which (str):
The specific volume to set. Can be ``Beep``, ``PCM`` or
``_all_``. ``Beep`` controls the volume for :meth:`beep` and
:meth:`play_notes`. ``PCM`` controls the volume for
:meth:`play_file` and :meth:`say`. ``_all_`` sets both at the
same time.
"""
pass