Skip to content

Commit

Permalink
Merge branch 'beta' into lo/tightly-couple-proxy-logic-to-key
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeocodes authored Nov 22, 2023
2 parents 44796b3 + a75db1f commit 164e5f1
Show file tree
Hide file tree
Showing 7 changed files with 240 additions and 91 deletions.
70 changes: 68 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,21 @@

Official JavaScript SDK for [Deepgram](https://www.deepgram.com/). Power your apps with world-class speech and Language AI models.

- [Migrating from v2](#migrating-from-v2)
- [Installation](#installation)
- [UMD](#umd)
- [ESM](#esm)
- [Initialization](#initialization)
- [Getting an API Key](#getting-an-api-key)
- [Scoped Configuration](#scoped-configuration)
- [Rest requests in the browser](#rest-requests-in-the-browser)
- [Transcription](#transcription)
- [Transcription (Synchronous)](#transcription-synchronous)
- [Remote Files](#remote-files)
- [Local Files](#local-files)
- [Transcription (Asynchronous / Callbacks)](#transcription-asynchronous--callbacks)
- [Remote Files](#remote-files-1)
- [Local Files](#local-files-1)
- [Transcription (Live / Streaming)](#transcription-live--streaming)
- [Live Audio](#live-audio)
- [Transcribing to captions](#transcribing-to-captions)
- [Projects](#projects)
Expand Down Expand Up @@ -51,8 +56,13 @@ Official JavaScript SDK for [Deepgram](https://www.deepgram.com/). Power your ap
- [Create On-Prem credentials](#create-on-prem-credentials)
- [Delete On-Prem credentials](#delete-on-prem-credentials)
- [Development and Contributing](#development-and-contributing)
- [Debugging and making changes locally](#debugging-and-making-changes-locally)
- [Getting Help](#getting-help)

# Migrating from v2

We have published [a migration guide on our docs](https://developers.deepgram.com/docs/js-sdk-v2-to-v3-migration-guide), showing how to move from v2 to v3.

# Installation

You can install this SDK directly from [npm](https://www.npmjs.com/package/@deepgram/sdk).
Expand Down Expand Up @@ -150,7 +160,7 @@ Your proxy service should replace the Authorization header with `Authorization:

Check out our example Node-based proxy here: [Deepgram Node Proxy](https://github.com/deepgram-devs/deepgram-node-proxy).

# Transcription
# Transcription (Synchronous)

## Remote Files

Expand Down Expand Up @@ -191,6 +201,58 @@ const { result, error } = await deepgram.listen.prerecorded.transcribeFile(

[See our API reference for more info](https://developers.deepgram.com/reference/pre-recorded).

# Transcription (Asynchronous / Callbacks)

## Remote Files

```js
import { CallbackUrl } from "@deepgram/sdk";

const { result, error } = await deepgram.listen.prerecorded.transcribeUrlCallback(
{
url: "https://dpgr.am/spacewalk.wav",
},
new CallbackUrl("http://callback/endpoint"),
{
model: "nova",
}
);
```

[See our API reference for more info](https://developers.deepgram.com/reference/pre-recorded).

## Local Files

```js
import { CallbackUrl } from "@deepgram/sdk";

const { result, error } = await deepgram.listen.prerecorded.transcribeFileCallback(
fs.createReadStream("./examples/spacewalk.wav"),
new CallbackUrl("http://callback/endpoint"),
{
model: "nova",
}
);
```

or

```js
import { CallbackUrl } from "@deepgram/sdk";

const { result, error } = await deepgram.listen.prerecorded.transcribeFileCallback(
fs.readFileSync("./examples/spacewalk.wav"),
new CallbackUrl("http://callback/endpoint"),
{
model: "nova",
}
);
```

[See our API reference for more info](https://developers.deepgram.com/reference/pre-recorded).

# Transcription (Live / Streaming)

## Live Audio

```js
Expand Down Expand Up @@ -503,6 +565,10 @@ To make sure our community is safe for all, be sure to review and agree to our
[Code of Conduct](./CODE_OF_CONDUCT.md). Then see the
[Contribution](./CONTRIBUTING.md) guidelines for more information.

## Debugging and making changes locally

If you want to make local changes to the SDK and run the [`examples/`](./examples/), you'll need to `npm run build` first, to ensure that your changes are included in the examples that are running.

# Getting Help

We love to hear from you so if you have questions, comments or find a bug in the
Expand Down
3 changes: 1 addition & 2 deletions examples/node-live/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const { createClient } = require("../../dist/main/index");
const { LiveTranscriptionEvents } = require("../../dist/main/lib/enums");
const { createClient, LiveTranscriptionEvents } = require("../../dist/main/index");
const fetch = require("cross-fetch");

const live = async () => {
Expand Down
33 changes: 8 additions & 25 deletions examples/node-prerecorded/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { createClient } = require("../../dist/main/index");
const fs = require("fs");

const url = async () => {
const transcribeUrl = async () => {
const deepgram = createClient(process.env.DEEPGRAM_API_KEY);

const { result, error } = await deepgram.listen.prerecorded.transcribeUrl(
Expand All @@ -13,25 +13,11 @@ const url = async () => {
}
);

if (error) throw new Error(error);
if (!error) console.log(result);
if (error) throw error;
if (!error) console.dir(result, { depth: null });
};

const readstream = async () => {
const deepgram = createClient(process.env.DEEPGRAM_API_KEY);

const { result, error } = await deepgram.listen.prerecorded.transcribeFile(
fs.createReadStream("./examples/nasa.mp4"),
{
model: "nova",
}
);

if (error) throw new Error(error);
if (!error) console.log(result);
};

const buffer = async () => {
const transcribeFile = async () => {
const deepgram = createClient(process.env.DEEPGRAM_API_KEY);

const { result, error } = await deepgram.listen.prerecorded.transcribeFile(
Expand All @@ -41,12 +27,9 @@ const buffer = async () => {
}
);

if (error) throw new Error(error);
if (!error) console.log(result);
if (error) throw error;
if (!error) console.dir(result, { depth: null });
};

(async () => {
await url();
await readstream();
await buffer();
})();
transcribeUrl();
transcribeFile();
Loading

0 comments on commit 164e5f1

Please sign in to comment.