AssemblyAI / assemblyai-node-sdk

The AssemblyAI JavaScript SDK provides an easy-to-use interface for interacting with the AssemblyAI API, which supports async and real-time transcription, audio intelligence models, as well as the latest LeMUR models.
https://www.assemblyai.com
MIT License
38 stars 11 forks source link

Typescript instructions are incorrect wrt remote vs local audio files #66

Closed jeffgca closed 2 months ago

jeffgca commented 2 months ago

For this page in the docs:

https://www.assemblyai.com/docs/getting-started/transcribe-an-audio-file

It says:

If you already have an audio file on your computer, you can also specify a local path, for example ./5_common_sports_injuries.mp3.

This fails with this error message:

Error: Transcript creation error, audio_url should start with http
    at TranscriptService.fetch (file:///Users/jeff/code/projects/little-bear/assembly/node_modules/assemblyai/dist/node.mjs:95:27)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async TranscriptService.fetchJson (file:///Users/jeff/code/projects/little-bear/assembly/node_modules/assemblyai/dist/node.mjs:103:26)
    at async TranscriptService.submit (file:///Users/jeff/code/projects/little-bear/assembly/node_modules/assemblyai/dist/node.mjs:498:22)
    at async TranscriptService.transcribe (file:///Users/jeff/code/projects/little-bear/assembly/node_modules/assemblyai/dist/node.mjs:460:28)
    at async run (file:///Users/jeff/code/projects/little-bear/assembly/id_speakers.js:25:22)

My code:

// Start by making sure the `assemblyai` package is installed.
// If not, you can install it by running the following command:
// npm install assemblyai

import { AssemblyAI } from "assemblyai";

const client = new AssemblyAI({
  apiKey: "***",
});

// const FILE_URL = "https://storage.googleapis.com/aai-web-samples/5_common_sports_injuries.mp3";

const FILE_URL = "./demo.mp3";

// You can also transcribe a local file by passing in a file path
// const FILE_URL = "./path/to/file.mp3";

// Request parameters where speaker_labels has been enabled
const data = {
  audio_url: FILE_URL,
  speaker_labels: true,
};

const run = async () => {
  const transcript = await client.transcripts.transcribe(data);
  console.log(transcript.text);

  // for (let utterance of transcript.utterances) {
  //   console.log(`Speaker ${utterance.speaker}: ${utterance.text}`);
  // }
};

run();
Swimburger commented 2 months ago

Hi @jeffgca, I removed your API key from the code you shared here. Make sure to reset your API key in the dashboard so the old key which is now compromised, stops working.

Swimburger commented 2 months ago

When you use audio_url, the configured string is taken as is and no pre-processing is done to it. However, you can use the audio option which accepts file paths, URLs, buffers, streams, and data-URLs.

jeffgca commented 2 months ago

When you use audio_url, the configured string is taken as is and no pre-processing is done to it. However, you can use the audio option which accepts file paths, URLs, buffers, streams, and data-URLs.

Thanks for replying so quickly, and sorry about the api key.

This is the boilerplate code from the onboarding process:

// Start by making sure the `assemblyai` package is installed.
// If not, you can install it by running the following command:
// npm install assemblyai

import { AssemblyAI } from 'assemblyai';

const client = new AssemblyAI({
  apiKey: '***',
});

const FILE_URL =
  'https://storage.googleapis.com/aai-web-samples/5_common_sports_injuries.mp3';

// You can also transcribe a local file by passing in a file path
// const FILE_URL = './path/to/file.mp3';

// Request parameters where speaker_labels has been enabled
const data = {
  audio_url: FILE_URL,
  speaker_labels: true
}

const run = async () => {
  const transcript = await client.transcripts.transcribe(data);
  console.log(transcript.text);

  for (let utterance of transcript.utterances) {
    console.log(`Speaker ${utterance.speaker}: ${utterance.text}`);
  }
};

run();

You should probably expand this boilerplate code to mention that, maybe something like:

// Start by making sure the `assemblyai` package is installed.
// If not, you can install it by running the following command:
// npm install assemblyai

import { AssemblyAI } from 'assemblyai';

const client = new AssemblyAI({
  apiKey: '***',
});

const FILE_URL =
  'https://storage.googleapis.com/aai-web-samples/5_common_sports_injuries.mp3';

// Request parameters where speaker_labels has been enabled
const data = {
  audio_url: FILE_URL,
  speaker_labels: true
}

// You can also transcribe a local file by passing in a file path
// const FILE_PATH = './path/to/file.mp3';
// const data = {
//    audio: FILE_PATH,
//    speaker_labels: true
// }

const run = async () => {
  const transcript = await client.transcripts.transcribe(data);
  console.log(transcript.text);

  for (let utterance of transcript.utterances) {
    console.log(`Speaker ${utterance.speaker}: ${utterance.text}`);
  }
};

run();
Swimburger commented 2 months ago

Thank you for catching that! I'll update the onboarding scripts and get back to you.

Swimburger commented 2 months ago

The samples have been update to use the audio option. Thank you for reporting!