Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/eighty-olives-tie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@livekit/agents-plugin-phonic': patch
---

Update Phonic plugin languages fields
4 changes: 3 additions & 1 deletion plugins/phonic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ Set the `PHONIC_API_KEY` environment variable, or pass `apiKey` directly to `Rea
| `welcomeMessage` | `string` | Message the agent says when the conversation starts. Ignored when `generateWelcomeMessage` is true |
| `generateWelcomeMessage` | `boolean` | Auto-generate the welcome message (ignores `welcomeMessage`) |
| `project` | `string` | Project name (default: `main`) |
| `languages` | `string[]` | ISO 639-1 language codes the agent should recognize and speak |
| `defaultLanguage` | `string` | ISO 639-1 default language for recognition and speech |
| `additionalLanguages` | `string[]` | Further ISO 639-1 codes (must not repeat `defaultLanguage`) |
| `multilingualMode` | `'auto'` \| `'request'` | Per-utterance language detection vs. change on user request (recommended: `request`) |
| `audioSpeed` | `number` | Audio playback speed |
| `phonicTools` | `string[]` | [Phonic Webhook tool](https://docs.phonic.co/docs/using-tools/tools_overview#webhook-tools) names available to the assistant |
| `boostedKeywords` | `string[]` | Keywords to boost in speech recognition |
Expand Down
2 changes: 1 addition & 1 deletion plugins/phonic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"typescript": "^5.0.0"
},
"dependencies": {
"phonic": "^0.31.2"
"phonic": "^0.31.8"
},
"peerDependencies": {
"@livekit/agents": "workspace:*",
Expand Down
49 changes: 45 additions & 4 deletions plugins/phonic/src/realtime/realtime_model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ export interface RealtimeModelOptions {
project?: string;
connOptions: APIConnectOptions;
baseUrl?: string;
languages?: string[];
defaultLanguage?: string;
additionalLanguages?: string[];
multilingualMode?: 'auto' | 'request';
audioSpeed?: number;
phonicTools?: string[];
boostedKeywords?: string[];
Expand Down Expand Up @@ -85,7 +87,21 @@ export class RealtimeModel extends llm.RealtimeModel {
*/
project?: string;
/**
* ISO 639-1 language codes the agent should recognize and speak
* ISO 639-1 default language for recognition and speech
*/
defaultLanguage?: string;
/**
* Further ISO 639-1 codes (must not include `defaultLanguage`)
*/
additionalLanguages?: string[];
/**
* `auto`: detect language per utterance. `request`: switch only when the user asks (recommended).
*/
multilingualMode?: 'auto' | 'request';
/**
* Deprecated. Use `defaultLanguage` and `additionalLanguages` instead.
* When both of those are omitted and this is set, `languages[0]` is the default
* language and `languages.slice(1)` are additional languages.
*/
languages?: string[];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you want to leave this in there for backwards compatibility for a bit?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, added this field back in.

/**
Expand Down Expand Up @@ -137,14 +153,31 @@ export class RealtimeModel extends llm.RealtimeModel {
throw new Error('Phonic API key is required. Provide apiKey or set PHONIC_API_KEY.');
}

let defaultLanguage = options.defaultLanguage;
let additionalLanguages = options.additionalLanguages;
if (
options.languages !== undefined &&
options.defaultLanguage === undefined &&
options.additionalLanguages === undefined
) {
if (options.languages.length > 0) {
defaultLanguage = options.languages[0];
}
if (options.languages.length > 1) {
additionalLanguages = options.languages.slice(1);
}
}

this._options = {
apiKey,
voice: options.voice,
phonicAgent: options.phonicAgent,
project: options.project,
welcomeMessage: options.welcomeMessage,
generateWelcomeMessage: options.generateWelcomeMessage,
languages: options.languages,
defaultLanguage,
additionalLanguages,
multilingualMode: options.multilingualMode,
audioSpeed: options.audioSpeed,
phonicTools: options.phonicTools,
boostedKeywords: options.boostedKeywords,
Expand Down Expand Up @@ -457,7 +490,15 @@ export class RealtimeSession extends llm.RealtimeSession {
voice_id: this.options.voice,
input_format: 'pcm_44100',
output_format: 'pcm_44100',
recognized_languages: this.options.languages,
...(this.options.defaultLanguage !== undefined && {
default_language: this.options.defaultLanguage,
}),
...(this.options.additionalLanguages !== undefined && {
additional_languages: this.options.additionalLanguages,
}),
...(this.options.multilingualMode !== undefined && {
multilingual_mode: this.options.multilingualMode,
}),
audio_speed: this.options.audioSpeed,
tools: [...(this.options.phonicTools ?? []), ...this.toolDefinitions],
boosted_keywords: this.options.boostedKeywords,
Expand Down
33 changes: 26 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading