Skip to content

Commit

Permalink
feat: add SpeakClient and example
Browse files Browse the repository at this point in the history
  • Loading branch information
SandraRodgers committed Jul 3, 2024
1 parent 54036a3 commit ce206d1
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions examples/node-speak-live/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const { createClient, LiveTTSEvents } = require("../../dist/main/index");
const fetch = require("cross-fetch");

const live = async () => {
const text = "Hello, how can I help you today?";

const deepgram = createClient(process.env.DEEPGRAM_API_KEY, {
global: { fetch: { options: { url: "https://api.beta.deepgram.com" } } },
});

const connection = deepgram.speak.live({ text }, { model: "aura-asteria-en" });

connection.on(LiveTTSEvents.Open, () => {
connection.on(LiveTTSEvents.Close, () => {
console.log("Connection closed.");
});

connection.on(LiveTTSEvents.Metadata, (data) => {
console.log(`Deepgram Metadata: ${data}`);
});

connection.on(LiveTTSEvents.Audio, (data) => {
console.log(`Deepgram Audio: ${data}`);
});

connection.on(LiveTTSEvents.Flushed, (data) => {
console.log("Deepgram Flushed");
});

connection.on(LiveTTSEvents.Error, (err) => {
console.error(err);
});

fetch(url)
.then((r) => r.body)
.then((res) => {
res.on("readable", () => {
connection.send(res.read());
});
});
});
};

live();

0 comments on commit ce206d1

Please sign in to comment.