import { nanoid } from 'nanoid'; import { createServer } from 'http'; import { Server } from 'socket.io'; import WebSocket from 'ws'; import sha256 from 'sha256';

const httpServer = createServer(); const wss = new Server(httpServer);

httpServer.listen(3000, () => { console.log('Server is running on port 3000'); });

wss.on('connection', ws => { const appId = '0c1b5e4ca7aaa024'; const secretKey = 'dPRBMN0Yskb3KvB5JWRTAFclDAmO6fu3';

const salt = nanoid(); const curtime = new Date(); const sign = sha256(appId + salt + curtime + secretKey); const signType = 'v4'; const langType = 'zh-CHS'; const format = 'mp3'; const channel = '1'; const version = 'v1'; const rate = '16000';

const params = appKey=${appId}&salt=${salt}&curtime=${curtime}&sign=${sign}&signType=${signType}&langType=${langType}&format=${format}&channel=${channel}&version=${version}&rate=${rate}; console.log(params);

const youdaoWs = new WebSocket(wss://openapi.youdao.com/stream_asropenapi?${params}); youdaoWs.addEventListener('open', () => { console.log('Connected to the server'); });

youdaoWs.addEventListener("message", ({ data }) => { console.log(data); });

ws.on('message', data => { ws.send(data + 'hello'); });

ws.on('close', () => { console.log('Connection closed'); }); })

import nanoid from nanoid;import createServer from http;import Server from socketio;const httpServer = createServer;const wss = new ServerhttpServerhttpServerlisten3000 = consolelogServer i

原文地址: https://www.cveoy.top/t/topic/h03Z 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录