Logs Not Displaying Inside WebSocket Connection

I’m integrating Yandex SpeechKit for speech-to-text recognition in my application. I’m following the documentation provided by Yandex: https://yandex.cloud/en/docs/speechkit/stt/api/streaming-examples#node_1

The connection is working, but I’m facing an issue where the logs related to the recognition process are not being displayed in the console.

Please help

const express = require('express');
const http = require('http');
const WebSocket = require('ws');
const fs = require('fs');
const grpc = require('grpc');
const protoLoader = require('@grpc/proto-loader');

const apiKey = '**************';

const app = express();
const server = http.createServer(app);
const wss = new WebSocket.Server({ server });

// Load Yandex STT service proto file
const packageDefinition = protoLoader.loadSync('../yandex/cloud/ai/stt/v2/stt_service.proto', {
    includeDirs: ['node_modules/google-proto-files', '..']
});
const packageObject = grpc.loadPackageDefinition(packageDefinition);
const serviceConstructor = packageObject.yandex.cloud.ai.stt.v2.SttService;
const grpcCredentials = grpc.credentials.createSsl(fs.readFileSync('./roots.pem'));
const service = new serviceConstructor('stt.api.cloud.yandex.net:443', grpcCredentials);

// Set up gRPC metadata
const serviceMetadata = new grpc.Metadata();
serviceMetadata.add('authorization', `Api-Key ${apiKey}`);

// Yandex STT request configuration
const requestConfig = {
    config: {
        specification: {
            languageCode: 'ru-RU',
            profanityFilter: true,
            model: 'general',
            partialResults: true,
            audioEncoding: 'LINEAR16_PCM',
            sampleRateHertz: 8000 // Ensure it's a number, not a string
        },
    }
};

let audioInput = [];
let recognizeStream = null;
process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0;

app.get('/', function(req, res) {
    res.send('<h1>Hello world!</h1>');
});

wss.on('connection', (ws) => {
    console.log('WebSocket connection established');
    // Create a writable stream
    var wstream = fs.createWriteStream('myBinaryFile');
    // Clear the current audioInput
    audioInput = [];
    // Initiate stream recognizing
    recognizeStream = service['StreamingRecognize'](serviceMetadata);

    recognizeStream.write(requestConfig)

    recognizeStream.on('data', (response) => {
        console.log('Start chunk: ');
        response.chunks[0].alternatives.forEach((alternative) => {
            console.log('Received transcription: ', alternative.text);
            ws.send(alternative.text);
            process.stdout.write(`Transcription: ${alternative.text}n`);
        });
        console.log('Is final: ', Boolean(response.chunks[0].final));
        console.log('');
    });

    recognizeStream.on('error', (err) => {
        console.error('gRPC Stream Error:', err);
        ws.close();
    });

    recognizeStream.on('end', () => {
        console.log('Recognition stream ended');
    });

    ws.on('close', () => {
        console.log('WebSocket connection closed');
        wstream.end();
        recognizeStream.end();
    });

    ws.on('message', (message) => {
        try {
            let data = JSON.parse(message);
            if (data.event === "media") {
                let b64data = data.media.payload;
                let buff = Buffer.from(b64data, 'base64');
                recognizeStream.write({ audioContent: buff });
                wstream.write(buff);
            }
        } catch (err) {
            console.error('Error processing message:', err);
            console.log('Message content:', message);
        }
    });

    ws.send('Hi there, I am a WebSocket server');
});

server.listen(3000, function() {
    console.log('listening on *:3000');
});

The problem is not with the authorization, as I’ve tested it with a simple example and it works fine. The issue is specifically with displaying logs

Logs regarding to ws are good

New contributor

Zhaneiro is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật