-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from AssemblyAI/E07417BDFEA3614F5967B1520F8B2F61
Release 4.0.0-beta.0
- Loading branch information
Showing
16 changed files
with
231 additions
and
71 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
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
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
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,59 @@ | ||
# SDK Compatibility | ||
|
||
The JavaScript SDK is developed for Node.js but is also compatible with other runtimes | ||
such as the browser, Deno, Bun, Cloudflare Workers, etc. | ||
|
||
## Browser compatibility | ||
|
||
To make the SDK compatible with the browser, the SDK aims to use web standards as much as possible. | ||
However, there are still incompatibilities between Node.js and the browser. | ||
|
||
- `RealtimeService` doesn't support the AssemblyAI API key in the browser. | ||
Instead, you have to generate a temporary auth token using `client.realtime.createTemporaryToken`, and pass in the resulting token to the real-time transcriber. | ||
|
||
Generate a temporary auth token on the server. | ||
|
||
```js | ||
import { AssemblyAI } from "assemblyai" | ||
// Ideally, to avoid embedding your API key client side, | ||
// you generate this token on the server, and pass it to the client via an API. | ||
const client = new AssemblyAI({ apiKey: "YOUR_API_KEY" }); | ||
const token = await client.realtime.createTemporaryToken({ expires_in = 480 }); | ||
``` | ||
|
||
> [!NOTE] | ||
> We recommend generating the token on the server, so you don't embed your AssemblyAI API key in your client app. | ||
> If you embed the API key on the client, everyone can see it and use it for themselves. | ||
Then pass the token via an API to the client. | ||
On the client, create an instance of `RealtimeService` using the token. | ||
|
||
```js | ||
import { RealtimeService } from "assemblyai"; | ||
// or the following if you're using UMD | ||
// const { RealtimeService } = assemblyai; | ||
|
||
const token = getToken(); // getToken is a function for you to implement | ||
|
||
const rt = new RealtimeService({ | ||
token: token, | ||
}); | ||
``` | ||
|
||
- You can't pass local audio file paths to `client.files.upload`, `client.transcripts.transcribe`, and `client.transcripts.submit`. If you do, you'll get the following error: "Function is not supported in this environment.". | ||
If you want to transcribe audio files, you must use a public URL, a stream, or a buffer. | ||
|
||
> [!WARNING] | ||
> The SDK is usable from the browser, but we strongly recommend you don't embed the AssemblyAI API key into your client apps. | ||
> If you embed the API key on the client, everyone can see it and use it for themselves. | ||
> Instead, create use the SDK on the server and provide APIs for your client to call. | ||
## Deno, Bun, Cloudflare Workers, etc. | ||
|
||
Most server-side JavaScript runtimes include a compatibility layer with Node.js. | ||
Our SDK is developed for Node.js, which makes it compatible with other runtimes through their compatibility layer. | ||
The bugs in these compatibility layers may introduce issues in our SDK. | ||
|
||
## Report issues | ||
|
||
If you find any (undocumented) bugs when using the SDK, [submit a GitHub issue](https://github.com/AssemblyAI/assemblyai-node-sdk). We'll try to fix it or at least document the compatibility issue. |
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
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 |
---|---|---|
@@ -1,26 +1,81 @@ | ||
const pkg = require("./package.json"); | ||
const ts = require("rollup-plugin-typescript2"); | ||
const terser = require("@rollup/plugin-terser"); | ||
const alias = require("@rollup/plugin-alias"); | ||
const { nodeResolve } = require("@rollup/plugin-node-resolve"); | ||
|
||
const cjsFile = pkg.main; | ||
const esmFile = pkg.module; | ||
const browserFile = pkg.exports["."].browser; | ||
|
||
const defaultPlugins = [ | ||
ts({ | ||
tsconfigOverride: { exclude: ["**/*.test.ts"] }, | ||
}), | ||
]; | ||
const defaultConfig = { | ||
plugins: defaultPlugins, | ||
external: ["fs", "isomorphic-ws", "@swimburger/isomorphic-streams"], | ||
input: "src/index.ts", | ||
}; | ||
|
||
const browserConfig = { | ||
...defaultConfig, | ||
plugins: [ | ||
...defaultConfig.plugins, | ||
alias({ | ||
entries: [{ find: "fs", replacement: "./src/browser/fs.ts" }], | ||
}), | ||
nodeResolve({ browser: true }), | ||
], | ||
external: [], | ||
}; | ||
|
||
module.exports = [ | ||
{ | ||
plugins: [ | ||
ts({ | ||
tsconfigOverride: { exclude: ["**/*.test.ts"] }, | ||
}), | ||
], | ||
external: ["axios", "fs", "stream", "ws"], | ||
input: "src/index.ts", | ||
...defaultConfig, | ||
output: [ | ||
{ | ||
file: pkg.main, | ||
file: cjsFile, | ||
format: "cjs", | ||
exports: "named", | ||
}, | ||
{ | ||
file: pkg.module, | ||
file: esmFile, | ||
format: "es", | ||
exports: "named", | ||
}, | ||
], | ||
}, | ||
{ | ||
...browserConfig, | ||
output: [ | ||
{ | ||
name: "assemblyai", | ||
file: browserFile, | ||
format: "esm", | ||
}, | ||
], | ||
}, | ||
{ | ||
...browserConfig, | ||
output: [ | ||
{ | ||
name: "assemblyai", | ||
file: "./dist/assemblyai.umd.js", | ||
format: "umd", | ||
}, | ||
], | ||
}, | ||
{ | ||
...browserConfig, | ||
plugins: [...browserConfig.plugins, terser()], | ||
output: [ | ||
{ | ||
name: "assemblyai", | ||
file: "./dist/assemblyai.umd.min.js", | ||
format: "umd", | ||
}, | ||
], | ||
}, | ||
]; |
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
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
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,8 @@ | ||
function throwError() { | ||
throw new Error("Function is not supported in this environment."); | ||
} | ||
|
||
export const createReadStream = throwError; | ||
export default { | ||
createReadStream, | ||
}; |
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
Oops, something went wrong.