Skip to main content

Text-to-Speech Example

This example demonstrates how to programmatically send text-to-speech (TTS) commands to your Aria Gen2 device using the Python SDK. You can use TTS to provide audio feedback, instructions, or notifications to the device wearer.

Quick Start

Run the text-to-speech example script:

python ~/Downloads/projectaria_client_sdk_samples_gen2/device_tts.py --text "Hello from Aria"

The device will speak the text through its built-in speakers.


What This Example Does

The script performs the following operations:

  1. Connects to the device
  2. Sends a text-to-speech command with your specified text
  3. The device converts the text to speech and plays it through the speakers
  4. Returns once the command is sent (device plays audio asynchronously)

Code Walkthrough

Step 1: Import Required Modules

import argparse
import aria.sdk_gen2 as sdk_gen2

Step 2: Parse Command-Line Arguments

def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser()
parser.add_argument(
"--text",
dest="text",
type=str,
default="",
required=True,
help="TTS text to rendered by the device.",
)
return parser.parse_args()

Required Argument:

  • --text: The text string you want the device to speak

Step 3: Connect to Device

device_client = sdk_gen2.DeviceClient()
config = sdk_gen2.DeviceClientConfig()
device_client.set_client_config(config)

try:
device = device_client.connect()
print(f"Connected to device {device.connection_id()}")
except Exception as e:
print(f"Failed to connect: {e}")
return

This establishes a connection to the first available device.


Step 4: Send Text-to-Speech Command

text = args.text
print(f"Sending text-to-speech: '{text}'")
device.render_tts(text)
print("Text-to-speech command sent successfully")

How it works:

  • The render_tts(text) method sends the text to the device
  • The device processes the text and generates speech
  • Audio is played through the device's built-in speakers
  • The function returns immediately (audio plays asynchronously)

Complete Example Code

Here's the full text-to-speech script:

import argparse
import aria.sdk_gen2 as sdk_gen2


def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser()
parser.add_argument(
"--text",
dest="text",
type=str,
default="",
required=True,
help="TTS text to rendered by the device.",
)
return parser.parse_args()


if __name__ == "__main__":
args = parse_args()

# Set up the device client to initiate connection to the device
device_client = sdk_gen2.DeviceClient()
# Set up the device client config to specify the device to be connected to e.g. device serial number.
# If nothing is specified, the first device in the list of connected devices will be connected to
config = sdk_gen2.DeviceClientConfig()

device_client.set_client_config(config)
device = device_client.connect()
print(f"Connected to device: {device.connection_id()}")
print(f"Rendering TTS: {args.text}")
device.render_tts(text=args.text)

Usage Examples

Simple Message

python ~/Downloads/projectaria_client_sdk_samples_gen2/device_tts.py --text "Recording started"

Multi-Word Message

python ~/Downloads/projectaria_client_sdk_samples_gen2/device_tts.py --text "Please look at the target"

Instructions

python ~/Downloads/projectaria_client_sdk_samples_gen2/device_tts.py --text "Turn left at the next intersection"

Numbers and Punctuation

python ~/Downloads/projectaria_client_sdk_samples_gen2/device_tts.py --text "You have 3 notifications. Check your device."

The TTS engine handles numbers and punctuation naturally.


Troubleshooting

TTS Command Sent But No Audio

Problem: The render_tts() command succeeds but device doesn't speak.

Solutions:

  1. Check device volume:

    • Ensure device audio is not muted
    • Check volume level in Companion App
  2. Check device status:

    • Verify device is powered on and functioning
    • Check battery level (low battery may affect audio)
  3. Verify connection:

    device = device_client.connect()
    print(f"Connected: {device.connection_id()}")
  4. Test with simple message:

    device.render_tts("Test")

Connection Lost During TTS

Problem: Device disconnects when sending TTS.

Solutions:

  1. Verify USB connection is stable
  2. Check authentication:
    aria_gen2 auth check
  3. Reconnect if needed:
    try:
    device.render_tts(text)
    except Exception as e:
    print(f"Connection lost: {e}")
    device = device_client.connect() # Reconnect
    device.render_tts(text) # Retry

Next Steps