Skip to content

Commit 331454e

Browse files
committed
feat: switch to new websocket logic
1 parent a7a4752 commit 331454e

14 files changed

Lines changed: 378 additions & 235 deletions

File tree

README.md

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ Official JavaScript SDK for [Deepgram](https://www.deepgram.com/). Power your ap
1414
- [1. Global Defaults](#1-global-defaults)
1515
- [2. Namespace-specific Configurations](#2-namespace-specific-configurations)
1616
- [3. Transport Options](#3-transport-options)
17-
- [Change the API url used for all SDK methods](#change-the-api-url-used-for-all-sdk-methods)
18-
- [Change the API url used for transcription only](#change-the-api-url-used-for-transcription-only)
19-
- [Override fetch transmitter](#override-fetch-transmitter)
20-
- [Proxy requests in the browser](#proxy-requests-in-the-browser)
21-
- [Set custom headers for fetch](#set-custom-headers-for-fetch)
17+
- [4. Examples](#4-examples)
18+
- [Change the API url used for all SDK methods](#change-the-api-url-used-for-all-sdk-methods)
19+
- [Change the API url used for transcription only](#change-the-api-url-used-for-transcription-only)
20+
- [Override fetch transmitter](#override-fetch-transmitter)
21+
- [Proxy requests in the browser](#proxy-requests-in-the-browser)
22+
- [Set custom headers for fetch](#set-custom-headers-for-fetch)
2223
- [Transcription (Synchronous)](#transcription-synchronous)
2324
- [Remote Files](#remote-files)
2425
- [Local Files](#local-files)
@@ -158,7 +159,9 @@ The SDK supports scoped configurtion. You'll be able to configure various aspect
158159

159160
This configuration system enables robust customization where defaults provide a foundation, but every aspect of the client's interaction with the API can be finely controlled and tailored to specific needs through namespace-specific settings. This enhances the maintainability and scalability of the application by localizing configurations to their relevant contexts.
160161

161-
## Change the API url used for all SDK methods
162+
## 4. Examples
163+
164+
### Change the API url used for all SDK methods
162165

163166
Useful for using different API environments (for e.g. beta).
164167

@@ -172,7 +175,7 @@ const deepgram = createClient(DEEPGRAM_API_KEY, {
172175
});
173176
```
174177

175-
## Change the API url used for transcription only
178+
### Change the API url used for transcription only
176179

177180
Useful for on-prem installations. Only affects requests to `/listen` endpoints.
178181

@@ -186,7 +189,7 @@ const deepgram = createClient(DEEPGRAM_API_KEY, {
186189
});
187190
```
188191

189-
## Override fetch transmitter
192+
### Override fetch transmitter
190193

191194
Useful for providing a custom http client.
192195

@@ -204,7 +207,7 @@ const deepgram = createClient(DEEPGRAM_API_KEY, {
204207
});
205208
```
206209

207-
## Proxy requests in the browser
210+
### Proxy requests in the browser
208211

209212
This SDK now works in the browser. If you'd like to make REST-based requests (pre-recorded transcription, on-premise, and management requests), then you'll need to use a proxy as we do not support custom CORS origins on our API. To set up your proxy, you configure the SDK like so:
210213

@@ -222,7 +225,7 @@ Your proxy service should replace the Authorization header with `Authorization:
222225

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

225-
## Set custom headers for fetch
228+
### Set custom headers for fetch
226229

227230
Useful for many things.
228231

@@ -635,7 +638,7 @@ const { result, error } = await deepgram.onprem.deleteCredentials(projectId, cre
635638

636639
Older SDK versions will receive Priority 1 (P1) bug support only. Security issues, both in our code and dependencies, are promptly addressed. Significant bugs without clear workarounds are also given priority attention.
637640

638-
We strictly follow semver, and will not introduce breaking changes to the publicly documented interfaces of the SDK. Use internal and undocumented interfaces without pinning your version, at your own risk.
641+
We strictly follow semver, and will not introduce breaking changes to the publicly documented interfaces of the SDK. **Use internal and undocumented interfaces without pinning your version, at your own risk.**
639642

640643
# Development and Contributing
641644

examples/browser-live/index.html

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<script src="../../dist/umd/deepgram.js"></script>
5+
<script>
6+
const { createClient } = deepgram;
7+
const _deepgram = createClient("deepgram-api-key", {
8+
global: {
9+
fetch: {
10+
options: {
11+
url: "https://api.mock.deepgram.com",
12+
},
13+
},
14+
},
15+
});
16+
17+
console.log("Deepgram Instance: ", _deepgram);
18+
19+
(async () => {
20+
const { result, error } = await _deepgram.manage.getProjects();
21+
22+
console.log(result, error);
23+
})();
24+
25+
// ...
26+
</script>
27+
</head>
28+
<body>
29+
Running test... check the developer console.
30+
</body>
31+
</html>

examples/browser-prerecorded/index.html

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,34 @@
1616

1717
console.log("Deepgram Instance: ", _deepgram);
1818

19-
(async () => {
20-
const { result, error } = await _deepgram.manage.getProjects();
19+
const transcribeUrl = async () => {
20+
const { result, error } = await _deepgram.listen.prerecorded.transcribeUrl(
21+
{
22+
url: "https://dpgr.am/spacewalk.wav",
23+
},
24+
{
25+
model: "nova",
26+
}
27+
);
28+
29+
if (error) throw error;
30+
if (!error) console.dir(result, { depth: null });
31+
};
32+
33+
const transcribeFile = async () => {
34+
const { result, error } = await _deepgram.listen.prerecorded.transcribeFile(
35+
fs.readFileSync("./examples/nasa.mp4"),
36+
{
37+
model: "nova",
38+
}
39+
);
2140

22-
console.log(result, error);
23-
})();
41+
if (error) throw error;
42+
if (!error) console.dir(result, { depth: null });
43+
};
2444

45+
transcribeUrl();
46+
transcribeFile();
2547
// ...
2648
</script>
2749
</head>

0 commit comments

Comments
 (0)