S2S Agents¶
Overview¶
Agents in RAI are modular components that encapsulate specific functionalities and behaviors. They follow a consistent interface defined by the BaseAgent
class and can be combined to create complex robotic systems. The Speech to Speech Agents are used for voice-based interaction, and communicate with other agents.
SpeechToSpeechAgent¶
SpeechToSpeechAgent
is the abstract base class for locally deployable S2S Agents. It provides functionality to manage sound device integration, as well as defines the communication schema for integration with the rest of the system.
Class Definition¶
SpeechToSpeechAgent class definition
rai_s2s.s2s.agents.SpeechToSpeechAgent
¶
Bases: BaseAgent
Source code in rai_s2s/s2s/agents/s2s_agent.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 |
|
add_detection_model(model)
¶
Add a voice detection model to check before recording starts.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
BaseVoiceDetectionModel
|
The voice detection model to be added. |
required |
Source code in rai_s2s/s2s/agents/s2s_agent.py
293 294 295 296 297 298 299 300 301 302 303 |
|
run()
¶
Start the text-to-speech agent, initializing playback and launching the transcription thread.
Source code in rai_s2s/s2s/agents/s2s_agent.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
|
set_playback_state(state)
¶
Set the playback state of the system.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
state
|
(play, pause, stop)
|
The desired playback state: - "play": Start or resume playback. - "pause": Pause the current playback. - "stop": Stop playback and reset playback-related data and queues. |
"play"
|
Notes
- When state is "stop", this method:
- Resets the
current_speech_id
. - Generates a new
current_transcription_id
. - Initializes new audio and text queues.
- Clears previous playback data.
- Logs actions and transitions for debugging and monitoring purposes.
Source code in rai_s2s/s2s/agents/s2s_agent.py
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 |
|
stop()
¶
Clean exit the speech-to-speech agent, terminating playback and joining the transcription thread.
Source code in rai_s2s/s2s/agents/s2s_agent.py
349 350 351 352 353 354 355 356 357 358 |
|
Communication¶
The Agent communicates through two communication channels provided during initialization - from_human
and to_human
.
On the from_human
channel text transcribed from human voice is published.
On the to_human
channel receives text to be played to the human through text-to-speech.
Voice interaction¶
The voice interaction is performed through two audio streams, with two devices.
These devices can be different, but don't have to - and in case of most local deployments they will be the same.
The list of available sounddevices for configuration can be obtained by running python -c "import sounddevice as sd; print(sd.query_devices())"
.
The configuration requires the user to specify the name of the sound device to be used for interfacing.
This is the entire string from the index until the comma before the hostapi (typically ALSA
on Ubuntu).
The voice interaction works as follows: - The user speaks, which leads to the VoiceActivityDetection
model activation. - [Optional] the recording pipeline (containing other models like OpenWakeWord) runs checks. - The recording starts. - The recording continues until the user stops talking (based on silence grace period). - The recording is transcribed and sent to the system. - The Agent receives text data to be played to the user. - The playback begins. - The playback can be interrupted by user speaking: - if there is additional recording pipeline the playback will pause while the user speaks (and continue, if the pipeline returns false). - otherwise the new recording will be send to the system, and transcription will stop the playback.
Implementations¶
ROS based implementation is available in ROS2S2SAgent
.
ROS2S2SAgent class definition
rai_s2s.s2s.agents.ros2s2s_agent.ROS2S2SAgent
¶
Bases: SpeechToSpeechAgent
Source code in rai_s2s/s2s/agents/ros2s2s_agent.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
|
See Also¶
- Models: For available voice based models and instructions for creating new ones.
- AutomaticSpeechRecognition: For AutomaticSpeechRecognitionAgent meant for distributed deployment.
- TextToSpeech: For TextToSpeechAgent meant for distributed deployment.