transcribe-stt v1.0.5
transcribe-stt
Transcribe audio of any length using Google's Speech to Text API
Contents
Description
Transcribe audio of any length using Google's Speech to Text API with its Node client
Installation
npm i transcribe-sttReference
See the reference documentation
Google authentication
To stream any audio, you must authenticate yourself with Google. To do this, just follow the steps below
- Complete step 1 (only) of Google's "quickstart" guide to create a GCP project and a private key. Save the private key in your project. (In this guide, we will call it
key.json) - Make sure any repo utilities ignore your new JSON key, e.g. by adding it to a
.gitignore:key.json Change the value of the environment variable
GOOGLE_APPLICATION_CREDENTIALSto the absolute path to your JSON key. There are multiple ways to do this. The easiest way is probably directly throughNodeDirectly through
NodeBefore using any
transcribe-sttservices, define the environment variableimport { resolve } from "path"; // Or in JavaScript: const { resolve } = require("path"); const filename = resolve(__dirname, "./key.json"); process.env.GOOGLE_APPLICATION_CREDENTIALS = filename;Define the relative path relative to the directory that the script is in.
Done!
dotenv(a package for easily defining environment variables)- Create a file called
.envand add it to any.gitignore/etc in the same way as the JSON key - In your
.env, add a line as follows, replacingPATHwith the absolute path to your JSON keyGOOGLE_APPLICATION_CREDENTIALS=PATH - Install
dotenvnpm i dotenv --save-dev Configure
dotenvbefore using anytranscribe-sttservicesimport { config } from "dotenv"; // Or in JavaScript: const { config } = require("dotenv"); config();Done!
- Create a file called
Command-line/shell
- Define environment variable, replacing
PATHwith the absolute path to your JSON key- Linux/macOS
export GOOGLE_APPLICATION_CREDENTIALS="PATH" - Windows
- PowerShell
$env:GOOGLE_APPLICATION_CREDENTIALS="PATH" - Command prompt
set GOOGLE_APPLICATION_CREDENTIALS=PATH
- PowerShell
- Linux/macOS
- Done!
- Define environment variable, replacing
Converting audio to WAV file
To use an audio file with transcribe-stt, it must be a WAV file with mono audio. This is a simple guide to converting audio files with an editor, specifically Audacity which is free and available on all 3 major operating systems. However, many of the steps will be very similar on any audio editing software
- Open the editor and import your audio
File > Import > Audio...
- Select all
Select > All
- Convert to mono if necessary
Tracks > Mix > Mix Stereo Down to Mono
- Optionally check or change the sample rate (and remember it for later)
Tracks > Resample...
- Export as WAV file
Export > Export as WAV
- Optionally change the encoding. When the export dialogue appears, there is an option to "Save as type" where you can choose what encoding you want (and remember it for later). Learn more about encodings below
To do
- Use docker
- Document how to change to a WAV file programmatically
- Allow advanced configuration options documented here
- Add
dataevent forDistributedSTTStream