Skip to content

Commit

Permalink
feat: switch to new websocket logic
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeocodes committed Jun 25, 2024
1 parent dae6890 commit d597a43
Show file tree
Hide file tree
Showing 14 changed files with 378 additions and 235 deletions.
25 changes: 14 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ Official JavaScript SDK for [Deepgram](https://www.deepgram.com/). Power your ap
- [1. Global Defaults](#1-global-defaults)
- [2. Namespace-specific Configurations](#2-namespace-specific-configurations)
- [3. Transport Options](#3-transport-options)
- [Change the API url used for all SDK methods](#change-the-api-url-used-for-all-sdk-methods)
- [Change the API url used for transcription only](#change-the-api-url-used-for-transcription-only)
- [Override fetch transmitter](#override-fetch-transmitter)
- [Proxy requests in the browser](#proxy-requests-in-the-browser)
- [Set custom headers for fetch](#set-custom-headers-for-fetch)
- [4. Examples](#4-examples)
- [Change the API url used for all SDK methods](#change-the-api-url-used-for-all-sdk-methods)
- [Change the API url used for transcription only](#change-the-api-url-used-for-transcription-only)
- [Override fetch transmitter](#override-fetch-transmitter)
- [Proxy requests in the browser](#proxy-requests-in-the-browser)
- [Set custom headers for fetch](#set-custom-headers-for-fetch)
- [Transcription (Synchronous)](#transcription-synchronous)
- [Remote Files](#remote-files)
- [Local Files](#local-files)
Expand Down Expand Up @@ -158,7 +159,9 @@ The SDK supports scoped configurtion. You'll be able to configure various aspect

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.

## Change the API url used for all SDK methods
## 4. Examples

### Change the API url used for all SDK methods

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

Expand All @@ -172,7 +175,7 @@ const deepgram = createClient(DEEPGRAM_API_KEY, {
});
```

## Change the API url used for transcription only
### Change the API url used for transcription only

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

Expand All @@ -186,7 +189,7 @@ const deepgram = createClient(DEEPGRAM_API_KEY, {
});
```

## Override fetch transmitter
### Override fetch transmitter

Useful for providing a custom http client.

Expand All @@ -204,7 +207,7 @@ const deepgram = createClient(DEEPGRAM_API_KEY, {
});
```

## Proxy requests in the browser
### Proxy requests in the browser

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:

Expand All @@ -222,7 +225,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).

## Set custom headers for fetch
### Set custom headers for fetch

Useful for many things.

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

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.

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.
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.**

# Development and Contributing

Expand Down
31 changes: 31 additions & 0 deletions examples/browser-live/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<html>
<head>
<script src="../../dist/umd/deepgram.js"></script>
<script>
const { createClient } = deepgram;
const _deepgram = createClient("deepgram-api-key", {
global: {
fetch: {
options: {
url: "https://api.mock.deepgram.com",
},
},
},
});

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

(async () => {
const { result, error } = await _deepgram.manage.getProjects();

console.log(result, error);
})();

// ...
</script>
</head>
<body>
Running test... check the developer console.
</body>
</html>
30 changes: 26 additions & 4 deletions examples/browser-prerecorded/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,34 @@

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

(async () => {
const { result, error } = await _deepgram.manage.getProjects();
const transcribeUrl = async () => {
const { result, error } = await _deepgram.listen.prerecorded.transcribeUrl(
{
url: "https://dpgr.am/spacewalk.wav",
},
{
model: "nova",
}
);

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

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

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

transcribeUrl();
transcribeFile();
// ...
</script>
</head>
Expand Down
Loading

0 comments on commit d597a43

Please sign in to comment.