This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1) | |
async function transcribeAudioStream(audio, cb) { | |
// 2) | |
const recognizeStream = speechClient.streamingRecognize(request) | |
// 3) | |
.on('data', function(data){ | |
console.log(data); | |
cb(data); | |
}) | |
// 4) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1) | |
speechClient = new speech.SpeechClient(); | |
// 2) | |
request = { | |
config: { | |
sampleRateHertz: sampleRateHertz, | |
encoding: encoding, | |
languageCode: languageCode | |
}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1) | |
async function detectIntentStream(audio, cb) { | |
// 2) | |
const stream = sessionClient.streamingDetectIntent() | |
.on('data', function(data){ | |
// 3) | |
if (data.recognitionResult) { | |
console.log( | |
`Intermediate transcript: | |
${data.recognitionResult.transcript}` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1) | |
sessionId = uuid.v4(); | |
// 2) | |
sessionClient = new df.SessionsClient(); | |
sessionPath = sessionClient.sessionPath(projectId, sessionId); | |
// 3) | |
request = { | |
session: sessionPath, | |
queryInput: { | |
// 4) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//1 | |
io.on('connect', (client) => { | |
//2 | |
client.on('message', async function(data) { | |
const dataURL = data.audio.dataURL.split(',').pop(); | |
let fileBuffer = Buffer.from(dataURL, 'base64'); | |
//3 ... | |
}); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1) | |
timeSlice: 4000, | |
// 2) | |
// as soon as the stream is available | |
ondataavailable: function(blob) { | |
// 3 | |
// making use of socket.io-stream for bi-directional | |
// streaming, create a stream |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1) | |
stopRecording.onclick = function() { | |
// recording stopped | |
startRecording.disabled = false; | |
stopRecording.disabled = true; | |
// stop audio recorder | |
recordAudio.stopRecording(function() { | |
// after stopping the audio, get the audio data | |
recordAudio.getDataURL(function(audioDataURL) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//1) | |
const startRecording = document.getElementById('start-recording'); | |
const stopRecording = document.getElementById('stop-recording'); | |
let recordAudio; | |
//2) | |
const socketio = io(); | |
const socket = socketio.on('connect', function() { | |
startRecording.disabled = false; | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const dialogflow = require('dialogflow'); | |
const client = new dialogflow.v2beta1.AgentsClient({ | |
// optional auth parameters. | |
}); | |
client.getValidationResult({}) | |
.then(responses => { | |
const response = responses[0]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const uuid = require('uuid'); | |
const df = require('dialogflow').v2beta1; | |
const sessionId = uuid.v4(); | |
const sessionClient = new df.SessionsClient(); | |
const sessionPath = sessionClient.sessionPath(projectId, sessionId); | |
let request = { | |
session: sessionPath, | |
queryInput: { |