Skip to content

Commit 6b25cca

Browse files
authored
Merge branch 'main' into chore/update-readme
2 parents d7c975b + 6739be8 commit 6b25cca

3 files changed

Lines changed: 47 additions & 158 deletions

File tree

examples/node-agent-live/index.js

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,36 @@ const { join } = require("path");
55

66
const deepgram = createClient(process.env.DEEPGRAM_API_KEY);
77

8+
// Add WAV header generation function
9+
function createWavHeader(audioData, sampleRate = 16000, channels = 1, bitsPerSample = 16) {
10+
const dataLength = audioData.length;
11+
const headerLength = 44;
12+
const fileLength = dataLength + headerLength - 8;
13+
14+
const header = Buffer.alloc(headerLength);
15+
16+
// RIFF header
17+
header.write("RIFF", 0);
18+
header.writeUInt32LE(fileLength, 4);
19+
header.write("WAVE", 8);
20+
21+
// fmt chunk
22+
header.write("fmt ", 12);
23+
header.writeUInt32LE(16, 16); // fmt chunk size
24+
header.writeUInt16LE(1, 20); // audio format (PCM)
25+
header.writeUInt16LE(channels, 22); // channels
26+
header.writeUInt32LE(sampleRate, 24); // sample rate
27+
header.writeUInt32LE((sampleRate * channels * bitsPerSample) / 8, 28); // byte rate
28+
header.writeUInt16LE((channels * bitsPerSample) / 8, 32); // block align
29+
header.writeUInt16LE(bitsPerSample, 34); // bits per sample
30+
31+
// data chunk
32+
header.write("data", 36);
33+
header.writeUInt32LE(dataLength, 40);
34+
35+
return header;
36+
}
37+
838
const agent = async () => {
939
let audioBuffer = Buffer.alloc(0);
1040
let i = 0;
@@ -106,7 +136,17 @@ const agent = async () => {
106136

107137
connection.on(AgentEvents.AgentAudioDone, async () => {
108138
console.log("Agent audio done");
109-
await writeFile(join(__dirname, `output-${i}.wav`), audioBuffer);
139+
140+
// Create WAV header and combine with audio data
141+
if (audioBuffer.length > 0) {
142+
const wavHeader = createWavHeader(audioBuffer);
143+
const wavFile = Buffer.concat([wavHeader, audioBuffer]);
144+
await writeFile(join(__dirname, `output-${i}.wav`), wavFile);
145+
console.log(`Wrote ${wavFile.length} bytes to output-${i}.wav`);
146+
} else {
147+
console.log("No audio data to write");
148+
}
149+
110150
audioBuffer = Buffer.alloc(0);
111151
i++;
112152
});

src/lib/types/AgentLiveSchema.ts

Lines changed: 6 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,4 @@
1-
type AudioEncoding =
2-
| "linear16"
3-
| "flac"
4-
| "mulaw"
5-
| "amr-nb"
6-
| "amr-wb"
7-
| "Opus"
8-
| "speex"
9-
| "g729"
10-
| string;
11-
12-
type ListenModel =
13-
| "nova-3"
14-
| "nova-3-general"
15-
| "nova-3-medical"
16-
| "nova-2"
17-
| "nova-2-meeting"
18-
| "nova-2-phonecall"
19-
| "nova-2-voicemail"
20-
| "nova-2-finance"
21-
| "nova-2-conversational"
22-
| "nova-2-video"
23-
| "nova-2-medical"
24-
| "nova-2-drivethru"
25-
| "nova-2-automotive"
26-
| "nova-2-atc"
27-
| "nova"
28-
| "nova-phonecall"
29-
| "enhanced"
30-
| "enhanced-meeting"
31-
| "enhanced-phonecall"
32-
| "enhanced-finance"
33-
| "base"
34-
| "base-meeting"
35-
| "base-phonecall"
36-
| "base-voicemail"
37-
| "base-finance"
38-
| "base-conversational"
39-
| "base-video"
40-
| "whisper-tiny"
41-
| "whisper"
42-
| "whisper-small"
43-
| "whisper-medium"
44-
| "whisper-large"
45-
| string;
46-
47-
type SpeakModel =
48-
| "aura-asteria-en"
49-
| "aura-luna-en"
50-
| "aura-stella-en"
51-
| "aura-athena-en"
52-
| "aura-hera-en"
53-
| "aura-orion-en"
54-
| "aura-arcas-en"
55-
| "aura-perseus-en"
56-
| "aura-angus-en"
57-
| "aura-orpheus-en"
58-
| "aura-helios-en"
59-
| "aura-zeus-en"
60-
| "aura-2-amalthea-en"
61-
| "aura-2-andromeda-en"
62-
| "aura-2-apollo-en"
63-
| "aura-2-arcas-en"
64-
| "aura-2-aries-en"
65-
| "aura-2-asteria-en"
66-
| "aura-2-athena-en"
67-
| "aura-2-atlas-en"
68-
| "aura-2-aurora-en"
69-
| "aura-2-callista-en"
70-
| "aura-2-cordelia-en"
71-
| "aura-2-cora-en"
72-
| "aura-2-cressida-en"
73-
| "aura-2-delia-en"
74-
| "aura-2-draco-en"
75-
| "aura-2-electra-en"
76-
| "aura-2-harmonia-en"
77-
| "aura-2-helena-en"
78-
| "aura-2-hera-en"
79-
| "aura-2-hermes-en"
80-
| "aura-2-hyperion-en"
81-
| "aura-2-iris-en"
82-
| "aura-2-janus-en"
83-
| "aura-2-juno-en"
84-
| "aura-2-jupiter-en"
85-
| "aura-2-luna-en"
86-
| "aura-2-mars-en"
87-
| "aura-2-minerva-en"
88-
| "aura-2-neptune-en"
89-
| "aura-2-odysseus-en"
90-
| "aura-2-ophelia-en"
91-
| "aura-2-orion-en"
92-
| "aura-2-orpheus-en"
93-
| "aura-2-pandora-en"
94-
| "aura-2-phoebe-en"
95-
| "aura-2-pluto-en"
96-
| "aura-2-saturn-en"
97-
| "aura-2-selene-en"
98-
| "aura-2-thalia-en"
99-
| "aura-2-theia-en"
100-
| "aura-2-vesta-en"
101-
| "aura-2-zeus-en"
102-
| string;
1+
type Provider = { type: string } & Record<string, unknown>;
1032

1043
/**
1054
* @see https://developers.deepgram.com/reference/voicebot-api-phase-preview#settingsconfiguration
@@ -115,7 +14,7 @@ interface AgentLiveSchema extends Record<string, unknown> {
11514
/**
11615
* @default "linear16"
11716
*/
118-
encoding: AudioEncoding;
17+
encoding: string;
11918
/**
12019
* @default 16000
12120
*/
@@ -141,46 +40,10 @@ interface AgentLiveSchema extends Record<string, unknown> {
14140
*/
14241
language?: string;
14342
listen?: {
144-
provider: {
145-
type: "deepgram";
146-
/**
147-
* @see https://developers.deepgram.com/docs/model
148-
*/
149-
model: ListenModel;
150-
/**
151-
* Only available for Nova 3.
152-
* @see https://developers.deepgram.com/docs/keyterm
153-
*/
154-
keyterms?: string[];
155-
};
43+
provider: Provider;
15644
};
15745
speak?: {
158-
provider: {
159-
type: "deepgram" | "eleven_labs" | "cartesia" | "open_ai" | string;
160-
/**
161-
* Deepgram OR OpenAI model to use.
162-
*/
163-
model?: SpeakModel;
164-
/**
165-
* Eleven Labs OR Cartesia model to use.
166-
*/
167-
model_id?: string;
168-
/**
169-
* Cartesia voice configuration.
170-
*/
171-
voice?: {
172-
mode: string;
173-
id: string;
174-
};
175-
/**
176-
* Optional Cartesia language.
177-
*/
178-
language?: string;
179-
/**
180-
* Optional Eleven Labs voice.
181-
*/
182-
language_code?: string;
183-
};
46+
provider: Provider;
18447
endpoint?: {
18548
url: string;
18649
headers?: Record<string, string>;
@@ -190,14 +53,7 @@ interface AgentLiveSchema extends Record<string, unknown> {
19053
* @see https://developers.deepgram.com/reference/voicebot-api-phase-preview#supported-llm-providers-and-models
19154
*/
19255
think?: {
193-
provider: {
194-
type: "deepgram" | "open_ai" | "anthropic" | "x_ai" | string;
195-
model: string;
196-
/**
197-
* 0-2 for OpenAI, 0-1 for Anthropic.
198-
*/
199-
temperature?: number;
200-
};
56+
provider: Provider;
20157
/**
20258
* Optional ONLY if LLM provider is OpenAI or Anthropic.
20359
*/
@@ -224,4 +80,4 @@ interface AgentLiveSchema extends Record<string, unknown> {
22480
};
22581
}
22682

227-
export type { AgentLiveSchema, SpeakModel };
83+
export type { AgentLiveSchema };

src/packages/AgentLiveClient.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { DEFAULT_AGENT_URL } from "../lib/constants";
22
import { AgentEvents } from "../lib/enums/AgentEvents";
3-
import { DeepgramError } from "../lib/errors";
43
import type { AgentLiveSchema, DeepgramClientOptions, FunctionCallResponse } from "../lib/types";
54
import { AbstractLiveClient } from "./AbstractLiveClient";
65

@@ -102,12 +101,6 @@ export class AgentLiveClient extends AbstractLiveClient {
102101
* @param options - The SettingsConfiguration object.
103102
*/
104103
public configure(options: AgentLiveSchema): void {
105-
if (
106-
!options.agent.listen?.provider.model.startsWith("nova-3") &&
107-
options.agent.listen?.provider.keyterms?.length
108-
) {
109-
throw new DeepgramError("Keyterms are only supported with the Nova 3 models.");
110-
}
111104
const string = JSON.stringify({
112105
type: "Settings",
113106
...options,

0 commit comments

Comments
 (0)