Sound
This file presents the different functions, enums and topics available with the Sound API
Sound - Command functions
This section reference all existing functions to control the Sound interface of the Ned2. All functions are accessible via an instance of the class NiryoRobot
robot = NiryoRobot(<robot_ip_address>)
robot.sound.play('connected.wav')
...
List of functions:
- class Sound(client)[source]
Sound robot functions
Example:
ros_instance = NiryoRos("127.0.0.1") # Hotspot sound_interface = Sound(ros_instance)
- Parameters
client (NiryoRos) – Niryo ROS client
Sound - Play
- Sound.play(sound_name, wait_end=False, start_time_sec=0, end_time_sec=0)[source]
Play a sound that as already been imported by the user on the robot.
Example:
# If you know that the sound test_sound.wav is already imported on the robot sound.play_sound_user("test_sound.wav") # If you want to play the first sound of the ones that are already on the robot without knowing its name sound_name = sound.get_sounds()[0] sound_duration = sound.play(sound_name) # Waits until the sound has been fully played sound_duration = sound.play(sound_name, wait_end=True) # Doesn't wait until the sound has been fully played sound_duration = sound.play(sound_name, wait_end=False) # Plays sound from 1.1 seconds from start to 4.3 seconds from start sound_duration = sound.play(sound_name, start_time_sec=1.1, end_time_sec=4.3)
- Sound.stop()[source]
Stop a sound being played. It will get automatically the name of the sound being played and stop it.
Example:
self.sound.stop()
- Return type
- property Sound.state
Returns the sound state client which can be used synchronously or asynchronously to obtain the current played sound.
Examples:
# Get last value sound.state() sound.state.value # Subscribe a callback def sound_callback(sound_name): print sound_name sound.state.subscribe(sound_callback) sound.state.unsubscribe()
- Returns
sound state topic instance
- Return type
- Sound.say(text, language=<Language.ENGLISH: 0>)[source]
Use gtts (Google Text To Speech) to interpret a string as sound
Languages available are:
- English: Language. ENGLISH - French: Language.FRENCH - Spanish: Language.SPANISH - Mandarin: Language.MANDARIN - Portuguese: Language.PORTUGUESE
Example
robot.say("Hello", Language.ENGLISH) robot.say("Bonjour", Language.FRENCH) robot.say("Hola", Language.SPANISH)
Sound - Volume
- property Sound.volume
Returns the volume state client which can be used synchronously or asynchronously to obtain the current volume.
Examples:
# Get last value sound.volume() sound.volume.value # Subscribe a callback def volume_callback(value): print value sound.volume.subscribe(volume_callback) sound.volume.unsubscribe()
- Returns
volume topic instance
- Return type
- Sound.get_volume()[source]
Returns the volume of the robot. The sound can be set between 0 (sound off) and 100 (sound max)
Examples:
# Get the volume of the sound sound.get_volume()
- Returns
int8 corresponding to the volume (0: sound off, 100: sound max)
- Return type
int8
- Sound.set_volume(sound_volume)[source]
Set the volume of the robot. You can set it between 0 and 100 (0: sound off and 100: sound max). If you put less than 0, the volume will be set to 0. If you put more than 100, the volume will be set to 100.
Example:
# Set the volume to 25 self.sound.set_volume(25) self.sound.play_sound_user("test_sound.wav")
- Parameters
sound_volume (int8) – Between O and 100 (0 sound off and 100 sound maximum)
- Return type
Sound - Manage
- property Sound.sounds
Returns the list of available sounds in the robot
Examples:
sounds_list = sound.sounds
- Sound.get_sounds()[source]
Returns the list of available sounds in the robot
Examples:
sounds_list = sound.get_sounds()
- Sound.save(sound_name, sound_path)[source]
Import a sound on the RaspberryPi of the robot. To do that, you will need the encoded data from a wav or mp3 sound. It is preferable to put the encoded data from the sound on a text file and directly read it from this file. You also need to give the name of the sound you want to import.
Example:
sound_name = "test_import_sound.wav" sound_path = "/home/niryo/test_sound.wav" ros_instance = pyniryo2.NiryoRos("10.10.10.10") sound = pyniryo2.Sound(ros_instance) sound.save(sound_name, sound_path) sound.play(sound_name)
- Sound.delete(sound_name)[source]
Delete a sound imported on the robot
Example:
self.sound.delete("test_sound.wav")
- Sound.get_sound_duration(sound_name)[source]
Get the duration of a sound in seconds
Examples:
sound_name = sound.get_sounds()[0] sound_duration = sound.get_sound_duration(sound_name) sound_duration = sound.get_sound_duration('test_sound.mp3')
- Returns
Returns the duration of a sound in seconds
- Return type
Sound - Niryo Topics
The use of these functions is explained in the NiryoTopics, section. They allow the acquisition of data in real time by callbacks or by direct call.
Name |
Function |
Return type |
---|---|---|
|
||
|
||
|