Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 63f24f3

Browse files
committed
add agent welcome message
Former-commit-id: 6eeb8fd Former-commit-id: 5d6223f3c076fac8200f4c47ee83d206175db7f9
1 parent 467e89d commit 63f24f3

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

examples/twilio/src/streams/textToAudio.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,32 @@ import { webSocketConnect } from "./connect";
33
import { DeepgramTextToSpeech } from "../functions/deepgram/textToSpeech";
44
import { v4 as uuidv4 } from "uuid";
55
import { StreamInput } from "./audioToText";
6+
import { TrackName } from "../workflows";
67

78
export async function streamTextToAudio({ streamSid, trackName }: StreamInput) {
89
return new Promise<void>(async (resolve, reject) => {
910
const ws = await webSocketConnect();
1011

1112
const textToSpeech = new DeepgramTextToSpeech();
1213

13-
textToSpeech.generate({
14+
const welcomeMessage = {
1415
gptReply: {
1516
partialResponseIndex: null,
1617
partialResponse:
1718
"Hello! My name is Emilia from Apple. You are interested in Airpods, is that correct?",
1819
},
1920
interactionCount: 0,
20-
trackName: "agent",
21-
});
21+
trackName: "agent" as TrackName,
22+
};
23+
24+
textToSpeech.generate(welcomeMessage);
25+
26+
const event = {
27+
streamSid,
28+
event: "answer",
29+
data: welcomeMessage,
30+
};
31+
ws.send(JSON.stringify(event));
2232

2333
ws.on("message", (data) => {
2434
const message = JSON.parse(data.toString());

0 commit comments

Comments
 (0)