
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
assemblyai
Advanced tools
The AssemblyAI Node.js SDK provides an easy-to-use interface for interacting with the AssemblyAI API, which supports async and real-time transcription, as well as the latest LeMUR models.
The AssemblyAI Node.js SDK provides an easy-to-use interface for interacting with the AssemblyAI API, which supports async and real-time transcription, as well as the latest LeMUR models.
You can install the AssemblyAI SDK by running:
npm install assemblyai
yarn add assemblyai
pnpm add assemblyai
bun add assemblyai
Import the AssemblyAI package and create an AssemblyAI object with your API key:
import AssemblyAI from "assemblyai";
const client = new AssemblyAI({
apiKey: process.env.ASSEMBLYAI_API_KEY,
})
You can now use the client
object to interact with the AssemblyAI API.
When you create a transcript, you can either pass in a URL to an audio file, or upload a file directly.
// Using a remote URL
const transcript = await client.transcripts.create({
audio_url: 'https://storage.googleapis.com/aai-web-samples/espn-bears.m4a',
})
// Uploading a file
const transcript = await client.transcripts.create({
audio_url: './news.mp4',
})
By default, when you create a transcript, it'll be polled until the status is completed
or error
.
You can configure whether to poll, the polling interval, and polling timeout using these options:
const transcript = await client.transcripts.create({
audio_url: 'https://storage.googleapis.com/aai-web-samples/espn-bears.m4a',
},
{
// Enable or disable polling. Defaults to true.
poll: true,
// How frequently the transcript is polled in ms. Defaults to 3000.
pollingInterval: 1000,
// How long to wait in ms until the "Polling timeout" error is thrown. Defaults to 180000.
pollingTimeout: 5000,
})
This will return the transcript object in its current state. If the transcript is still processing, the status
field will be queued
or processing
. Once the transcript is complete, the status
field will be completed
.
const transcript = await client.transcripts.get(transcript.id)
This will return a paged list of transcripts that you have transcript.
const page = await client.transcripts.list()
You can also paginate over all pages.
let nextPageUrl: string | null = null;
do {
const page = await client.transcripts.list(nextPageUrl)
nextPageUrl = page.page_details.next_url
} while(nextPageUrl !== null)
const res = await client.transcripts.delete(transcript.id)
Call LeMUR endpoints to summarize, ask questions, generate action items, or run a custom task.
Custom Summary:
const { response } = await client.lemur.summary({
transcript_ids: ['0d295578-8c75-421a-885a-2c487f188927'],
answer_format: 'one sentence',
context: {
speakers: ['Alex', 'Bob'],
}
})
Question & Answer:
const { response } = await client.lemur.questionAnswer({
transcript_ids: ['0d295578-8c75-421a-885a-2c487f188927'],
questions: [
{
question: 'What are they discussing?',
answer_format: 'text',
}
]
})
Action Items:
const { response } = await client.lemur.actionItems({
transcript_ids: ['0d295578-8c75-421a-885a-2c487f188927'],
})
Custom Task:
const { response } = await client.lemur.task({
transcript_ids: ['0d295578-8c75-421a-885a-2c487f188927'],
prompt: 'Write a haiku about this conversation.',
})
Create the real-time service.
const service = client.realtime.createService();
You can also pass in the following options.
const service = client.realtime.createService({
realtimeUrl: 'wss://localhost/override',
apiKey: process.env.ASSEMBLYAI_API_KEY // The API key passed to `AssemblyAI` will be used by default,
sampleRate: 16_000,
wordBoost: ['foo', 'bar']
});
You can also generate a temporary auth token for real-time.
const token = await client.realtime.createTemporaryToken({ expires_in = 60 });
const rt = client.realtime.createService({
token: token
});
[!WARNING] Storing your API key in client-facing applications exposes your API key. Generate a temporary auth token on the server and pass it to your client.
You can configure the following events.
rt.on("open", ({ sessionId, expiresAt }) => console.log('Session ID:', sessionId, 'Expires at:', expiresAt));
rt.on("close", (code: number, reason: string) => console.log('Closed', code, reason));
rt.on("transcript", (transcript: TranscriptMessage) => console.log('Transcript:', transcript));
rt.on("transcript.partial", (transcript: PartialTranscriptMessage) => console.log('Partial transcript:', transcript));
rt.on("transcript.final", (transcript: FinalTranscriptMessage) => console.log('Final transcript:', transcript));
rt.on("error", (error: Error) => console.error('Error', error));
After configuring your events, connect to the server.
await rt.connect();
Send audio data.
// Pseudo code for getting audio
getAudio((chunk) => {
rt.sendAudio(chunk);
});
Close the connection when you're finished.
await rt.close();
To run the test suite, first install the dependencies, then run pnpm test
:
pnpm install
pnpm test
FAQs
The AssemblyAI JavaScript SDK provides an easy-to-use interface for interacting with the AssemblyAI API, which supports async and real-time transcription, as well as the latest LeMUR models.
The npm package assemblyai receives a total of 46,529 weekly downloads. As such, assemblyai popularity was classified as popular.
We found that assemblyai demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.