-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
27 lines (26 loc) · 715 Bytes
/
index.js
File metadata and controls
27 lines (26 loc) · 715 Bytes
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
const speech = require("@google-cloud/speech");
const fs = require("fs");
async function main() {
const client = new speech.SpeechClient();
const filename = "./resources/audio.raw";
const file = fs.readFileSync(filename);
const audioBytes = file.toString("base64");
const audio = {
content: audioBytes
};
const config = {
encoding: "LINEAR16",
sampleRateHertz: 16000,
languageCode: "en-US"
};
const request = {
audio: audio,
config: config
};
const [response] = await client.recognize(request);
const transcription = response.results
.map(result => result.alternatives[0].transcript)
.join("/n");
console.log(transcription);
}
main().catch(console.error);