Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Syntax Speech to Text
import speech from '@google-cloud/speech';
import fs from 'fs';
import dotenv from 'dotenv';
async function main() {
const client = new speech.SpeechClient();
const config = {
encoding: 'MP3',
sampleRateHertz: 44100,
languageCode: 'en-US',
diarizationConfig: {
enableSpeakerDiarization: true,
minSpeakerCount: 2,
maxSpeakerCount: 3,
metadata: {
// 541511 Custom Computer Programming Services Web (i.e., Internet) page design services, custom
industryNaicsCodeOfAudio: 541511,
microphoneDistance: 'NEARFIELD',
originalMediaType: 'AUDIO',
recordingDeviceType: 'OTHER_INDOOR_DEVICE',
recordingDeviceName: 'Cardioid Microphone',
originalMimeType: 'audio/mp3',
audioTopic: 'Syntax Podcast',
speechContexts: [
phrases: [
'Hasty Treat',
'Wes Bos',
'Scott Tolinski',
'Log Rocket',
const audio = {
// uri: 'gs://syntax/Syntax287.mp3',
uri: 'gs://syntax/clip.mp3',
const request = {
// Detects speech in the audio file. This creates a recognition job that you
// can wait for now, or get its result later.
const [operation] = await client.longRunningRecognize(request);
// Get a Promise representation of the final result of the job
const [response] = await operation.promise();
const transcription = response.results
.map(result => result.alternatives[0].transcript)
console.log(`Transcription: ${transcription}`);
fs.writeFileSync('syntax3.txt', transcription);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment