From 9c024e17c41a6640629767f80e6abecdcbec4b81 Mon Sep 17 00:00:00 2001 From: David Lechner Date: Mon, 13 Jan 2020 20:04:57 -0600 Subject: [PATCH] pybricks/builtins: update speaker methods Update Speaker class with newly implemented methods --- doc/api/hubs_ev3brick.inc | 10 +-- doc/api/signaltypes.rst | 4 +- pybricks-projects | 2 +- pybricks/builtins.py | 138 ++++++++++++++++++++++++++++++++------ 4 files changed, 125 insertions(+), 29 deletions(-) diff --git a/doc/api/hubs_ev3brick.inc b/doc/api/hubs_ev3brick.inc index 3f47e39..1064a1f 100644 --- a/doc/api/hubs_ev3brick.inc +++ b/doc/api/hubs_ev3brick.inc @@ -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 diff --git a/doc/api/signaltypes.rst b/doc/api/signaltypes.rst index 96eb2f7..032bb5b 100644 --- a/doc/api/signaltypes.rst +++ b/doc/api/signaltypes.rst @@ -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 ` or :ref:`brightnesses `. -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: diff --git a/pybricks-projects b/pybricks-projects index 37ca782..fe3a7ae 160000 --- a/pybricks-projects +++ b/pybricks-projects @@ -1 +1 @@ -Subproject commit 37ca78217fdaf4e8c8d1b1df8384b6ad6604eb7a +Subproject commit fe3a7ae6363e8b270996434346ac5f5fd49bd4d8 diff --git a/pybricks/builtins.py b/pybricks/builtins.py index 566f3db..f21474e 100644 --- a/pybricks/builtins.py +++ b/pybricks/builtins.py @@ -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