Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const record = require('node-record-lpcm16');
- var mysql = require('mysql');
- var con = mysql.createConnection({
- host: "localhost",
- user: "edulux",
- password: "edulux",
- database: "edulux",
- });
- con.connect(function(err) {
- if (err) throw err;
- console.log("Connected!");
- });
- // Imports the Google Cloud client library
- const speech = require('@google-cloud/speech');
- // Creates a client
- const client = new speech.SpeechClient();
- /**
- * TODO(developer): Uncomment the following lines before running the sample.
- */
- const encoding = 'LINEAR16';
- const sampleRateHertz = 16000;
- const languageCode = 'en-US';
- const request = {
- config: {
- encoding: encoding,
- sampleRateHertz: sampleRateHertz,
- languageCode: languageCode,
- },
- interimResults: false, // If you want interim results, set this to true
- };
- // Create a recognize stream
- const recognizeStream = client
- .streamingRecognize(request)
- .on('error', console.error)
- .on('data', function(data){
- console.log(data.results[0]);
- if (data.results[0] && data.results[0].alternatives[0]){
- var sql = "INSERT INTO speechtotext (translation_text, data) VALUES (" + con.escape(data.results[0].alternatives[0].transcript) + " , 'testing')" ;
- //var values = [[''+connection.escape(data.results[0].alternatives[0].transcript), 'Navetz Test']];
- con.query(sql,function (err, result) {
- if (err) throw err;
- console.log("1 record inserted, ID: " + result.insertId);
- });
- }
- process.stdout.write(
- data.results[0] && data.results[0].alternatives[0]
- ? `Transcription: ${data.results[0].alternatives[0].transcript}\n`
- : `\n\nReached transcription time limit, press Ctrl+C\n`
- )
- });
- // Start recording and send the microphone input to the Speech API
- record
- .start({
- sampleRateHertz: sampleRateHertz,
- threshold: 0,
- // Other options, see https://www.npmjs.com/package/node-record-lpcm16#options
- verbose: false,
- recordProgram: 'rec', // Try also "arecord" or "sox"
- silence: '10.0',
- })
- .on('error', console.error)
- .pipe(recognizeStream);
- console.log('Listening, press Ctrl+C to stop.');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement