Skip to main content
Mastra v1 is coming in January 2026. Get ahead by starting new projects with the beta or upgrade your existing project today.

PlayAI

The PlayAI voice implementation in Mastra provides text-to-speech capabilities using PlayAI's API.

Usage ExampleDirect link to Usage Example

import { PlayAIVoice } from "@mastra/voice-playai";

// Initialize with default configuration (uses PLAYAI_API_KEY environment variable and PLAYAI_USER_ID environment variable)
const voice = new PlayAIVoice();

// Initialize with default configuration
const voice = new PlayAIVoice({
speechModel: {
name: "PlayDialog",
apiKey: process.env.PLAYAI_API_KEY,
userId: process.env.PLAYAI_USER_ID,
},
speaker: "Angelo", // Default voice
});

// Convert text to speech with a specific voice
const audioStream = await voice.speak("Hello, world!", {
speaker:
"s3://voice-cloning-zero-shot/b27bc13e-996f-4841-b584-4d35801aea98/original/manifest.json", // Dexter voice
});

Constructor ParametersDirect link to Constructor Parameters

speechModel?:

PlayAIConfig
= { name: 'PlayDialog' }
Configuration for text-to-speech functionality

speaker?:

string
= First available voice ID
Default voice ID to use for speech synthesis

PlayAIConfigDirect link to PlayAIConfig

name?:

'PlayDialog' | 'Play3.0-mini'
= 'PlayDialog'
The PlayAI model to use

apiKey?:

string
PlayAI API key. Falls back to PLAYAI_API_KEY environment variable

userId?:

string
PlayAI user ID. Falls back to PLAYAI_USER_ID environment variable

MethodsDirect link to Methods

speak()Direct link to speak()

Converts text to speech using the configured speech model and voice.

input:

string | NodeJS.ReadableStream
Text to convert to speech. If a stream is provided, it will be converted to text first.

options.speaker?:

string
= Constructor's speaker value
Override the default speaker for this request

Returns: Promise<NodeJS.ReadableStream>.

getSpeakers()Direct link to getSpeakers()

Returns an array of available voice options, where each node contains:

name:

string
Name of the voice

accent:

string
Accent of the voice (e.g., 'US', 'British', 'Australian')

gender:

'M' | 'F'
Gender of the voice

age:

'Young' | 'Middle' | 'Old'
Age category of the voice

style:

'Conversational' | 'Narrative'
Speaking style of the voice

voiceId:

string
Unique identifier for the voice

listen()Direct link to listen()

This method is not supported by PlayAI and will throw an error. PlayAI does not provide speech-to-text functionality.

NotesDirect link to Notes

  • PlayAI requires both an API key and a user ID for authentication
  • The service offers two models: 'PlayDialog' and 'Play3.0-mini'
  • Each voice has a unique S3 manifest ID that must be used when making API calls