generated from deepgram/oss-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
54036a3
commit ce206d1
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |