You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Not able to import in React.js | Not sure if browser support is available as no documentation about it #280
I am referring this sample to use the Speech APIs in my React.js application
below is what i am trying to do
import Speech from '@google-cloud/speech';
import record from 'node-record-lpcm16';
const speech = Speech();
const options = {
config: {
// Configure these settings based on the audio you're transcribing
encoding: 'LINEAR16',
sampleRate: 16000
}
};
// Create a recognize stream
const recognizeStream = speech.createRecognizeStream(options)
.on('error', console.error)
.on('data', (data) => process.stdout.write(data.results));
// Start recording and send the microphone input to the Speech API
record.start({ sampleRate: 16000 }).pipe(recognizeStream);
But this fails to instantiate the Speech object
Am i missing something or there is something which is not documented for use in React.js/Angular.js?
You can manually make an HTTP request to the Google Cloud Speech API from the browser. You'll need an API Key to authenticate. With Angular 1.x, it might be something like:
$http({method: 'POST',url: 'https://speech.googleapis.com/v1beta1/speech:syncrecognize',params: {key: 'YOUR_API_KEY'},data: {config: {encoding: 'LINEAR16',// customize for your audiosampleRate: 16000// customize for your audio},audio: {content: 'as0af8s7d0fa9sd7f='// base64-encoded string of the content of your audio file// or if your audio file is in Google Cloud Storage, "uri" instead:// uri: 'gs://your-bucket/your-audio-file'}}}).then(...);
I don't have a bigger example to give you at the moment, but when I do I'll post back here.
Activity
jmdobry commentedon Dec 21, 2016
Is your application something that runs in the browser or on the server (via Node.js)? The samples in this repository only run on the server.
rajiff commentedon Dec 21, 2016
@jmdobry it Brunson browser compiled using web pack on server for bundling
Can you suggest any alternative for using on browser or how we can change it, we can try change and create a pull request
jmdobry commentedon Dec 22, 2016
You can manually make an HTTP request to the Google Cloud Speech API from the browser. You'll need an API Key to authenticate. With Angular 1.x, it might be something like:
I don't have a bigger example to give you at the moment, but when I do I'll post back here.
rajiff commentedon Dec 23, 2016
Nice, only worry is, this will expose API key over browser, need to check
jmdobry commentedon Aug 21, 2017
That is the concern. We generally expect there to be a proxy between the browser and the Speech API, such as your own backend server.
refactor: simplify cloud_tasks_create_http_task_with_token (#280)
chore: release 2.2.2 (#280)
refactor: simplify cloud_tasks_create_http_task_with_token (#280)
chore: release 2.2.2 (#280)
chore: release 3.0.0 (#280)
chore: release 3.0.0 (#280)
chore: release 2.2.2 (#280)
chore: release 3.0.0 (#280)
chore: release 3.0.0 (#280)
chore: release 3.0.0 (#280)
ProductSearch GA (#280)
chore: release 2.2.2 (#280)
chore: release 3.0.0 (#280)
chore: release 2.2.2 (#280)
fix(deps): update dependency yargs to v13 (#280)
fix(deps): update dependency yargs to v13 (#280)
fix(deps): update dependency yargs to v13 (#280)
chore: release 3.8.1 (#280)
chore(main): release 1.19.0 (#281)
fix: overhauled quickstart (#280)
fix: overhauled quickstart (#280)
chore(main): release 1.19.0 (#281)