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-stt
Reference
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_CREDENTIALS
to the absolute path to your JSON key. There are multiple ways to do this. The easiest way is probably directly throughNode
-
Directly through
Node
-
Before using any
transcribe-stt
services, define the environment variable;// Or in JavaScript: const { resolve } = require("path");;process.env.GOOGLE_APPLICATION_CREDENTIALS = filename;Define the relative path relative to the directory that the script is in.
-
Done!
-
-
-
Create a file called
.env
and add it to any.gitignore
/etc in the same way as the JSON key -
In your
.env
, add a line as follows, replacingPATH
with the absolute path to your JSON keyGOOGLE_APPLICATION_CREDENTIALS=PATH
-
Install
dotenv
npm i dotenv --save-dev
-
Configure
dotenv
before using anytranscribe-stt
services;// Or in JavaScript: const { config } = require("dotenv");config; -
Done!
-
-
Command-line/shell
- Define environment variable, replacing
PATH
with 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
data
event forDistributedSTTStream