Skip to content

Chat Service

The chat service is a ROS2 node that orchestrates a full speech-to-speech chat pipeline. It takes an audio input, processes it through Speech-to-Text (STT), a Large Language Model (LLM), and Text-to-Speech (TTS) to generate a spoken response.

Dependencies

The chat_node requires the following services to be running and available:

  • /stt (ric_messages/srv/AudioBytesToText)
  • /llm (ric_messages/srv/LLMChat)
  • /tts (ric_messages/srv/TextToAudioBytes)

The node will wait indefinitely for these services to become available before it starts processing requests.

How to Run the Service

To run the chat service, you first need to source your ROS2 environment and then use the ros2 run command.

# Source your ROS2 workspace
source install/setup.bash

# Run the node
ros2 run chat service

When running the service in Docker, you can enter the container with the following command, where the above steps are already done:

docker exec -it chat-node bash

Parameters

You can customize the behavior of the node by passing the following ROS parameters.

ros2 run chat service --ros-args -p <parameter>:=<value>
Parameter Description Default
stt_service The service name for the Speech-to-Text (STT) node. /stt
llm_service The service name for the Large Language Model (LLM) node. /llm
tts_service The service name for the Text-to-Speech (TTS) node. /tts

How to Call the Service

You can call the /chat service using the ros2 service call command or the provided Python script.

Service Definition

/chat

To call the service from the command line, you need to provide the audio as an array of bytes.

  • Type: ric_messages/srv/Chat
  • Description: Takes an audio input, processes it through STT, LLM, and TTS, and returns the generated audio response along with metadata.
  • Request: uint8[] audio
  • Response: string language, string text, string emotion, uint8[] audio
ros2 service call /chat ric_messages/srv/Chat "{'audio': [0, 1, 2, ...]}"

Note: Providing a raw audio byte array via the command line is impractical for real audio files. This method is primarily for testing with very short or empty audio clips.

Using the Example Python Script

For actual use, it is recommended a ROS2 client like call_chat_service.py, which can read an audio file and send the ROS2 request.

call_chat_service.py can be used as test script, while the service is running. Use it as follows:

python3 call_chat_service.py <input.wav> <output.wav>
  • <input.wav>: The path to the input WAV file to be sent to the service.
  • <output.wav>: The path where the generated output WAV file will be saved.

Note that this will only output the response audio. Language, text and emotion will be discarded in the script.

Important: Before running the script, you may need to configure the output audio parameters (sample rate, bit depth, channels) at the top of the call_chat_service.py file to match the format produced by your TTS service. The script requires rclpy to be able to directly call the /chat service. The devcontainer already contains all requirements.

Response Example

A successful call will return a response object containing the generated audio and metadata:

response:
ric_messages.srv.Chat_Response(
    language='en',
    text='Hello! How can I help you today?',
    emotion='calm',
    audio=[...]
)