-
Notifications
You must be signed in to change notification settings - Fork 0
/
index copy 2.js
38 lines (32 loc) · 988 Bytes
/
index copy 2.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Imports the required modules
const fs = require('fs');
const speech = require('@google-cloud/speech');
// Creates a client
const client = new speech.SpeechClient();
async function quickstart() {
// The path to the local audio file
const filePath = 'C:/put_your_local_folder_here/tongue twister 1.mp3';
// Read the audio file
const file = fs.readFileSync(filePath);
const audioBytes = file.toString('base64');
// The audio file's encoding, sample rate in hertz, and BCP-47 language code
const audio = {
content: audioBytes,
};
const config = {
encoding: 'MP3',
sampleRateHertz: 48000,
languageCode: 'en-US',
};
const request = {
audio: audio,
config: config,
};
// Detects speech in the audio file
const [response] = await client.recognize(request);
const transcription = response.results
.map(result => result.alternatives[0].transcript)
.join('\n');
console.log(`Transcription: ${transcription}`);
}
quickstart();