Skip to content

Commit d4dfee7

Browse files
authored
Speech upgrade (#427)
* Upgrades speech client to semi-gapic * Adds library with streaming fixes
1 parent 94dca1c commit d4dfee7

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

packages/google-cloud-node/samples/package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
"test": "npm run system-test"
1919
},
2020
"dependencies": {
21-
"@google-cloud/speech": "0.9.3",
22-
"@google-cloud/storage": "1.1.1",
21+
"@google-cloud/speech": "^0.10.1",
22+
"@google-cloud/storage": "^1.2.0",
2323
"node-record-lpcm16": "0.3.0",
24-
"yargs": "8.0.2"
24+
"yargs": "^8.0.2"
2525
},
2626
"devDependencies": {
27-
"@google-cloud/nodejs-repo-tools": "1.4.15",
28-
"ava": "0.19.1",
27+
"@google-cloud/nodejs-repo-tools": "^1.4.15",
28+
"ava": "^0.19.1",
2929
"proxyquire": "1.8.0",
3030
"sinon": "2.3.4"
3131
},

packages/google-cloud-node/samples/quickstart.js

+16-4
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818
// [START speech_quickstart]
1919
// Imports the Google Cloud client library
2020
const Speech = require('@google-cloud/speech');
21+
const fs = require('fs');
2122

2223
// Your Google Cloud Platform project ID
23-
const projectId = 'YOUR_PROJECT_ID';
24+
const projectId = 'your-project-id';
2425

2526
// Instantiates a client
2627
const speechClient = Speech({
@@ -30,17 +31,28 @@ const speechClient = Speech({
3031
// The name of the audio file to transcribe
3132
const fileName = './resources/audio.raw';
3233

34+
// Reads a local audio file and converts it to base64
35+
const file = fs.readFileSync(fileName);
36+
const audioBytes = file.toString('base64');
37+
3338
// The audio file's encoding, sample rate in hertz, and BCP-47 language code
34-
const options = {
39+
const audio = {
40+
content: audioBytes
41+
};
42+
const config = {
3543
encoding: 'LINEAR16',
3644
sampleRateHertz: 16000,
3745
languageCode: 'en-US'
3846
};
47+
const request = {
48+
audio: audio,
49+
config: config
50+
};
3951

4052
// Detects speech in the audio file
41-
speechClient.recognize(fileName, options)
53+
speechClient.recognize(request)
4254
.then((results) => {
43-
const transcription = results[0];
55+
const transcription = results[0].results[0].alternatives[0].transcript;
4456
console.log(`Transcription: ${transcription}`);
4557
})
4658
.catch((err) => {

0 commit comments

Comments
 (0)