Git Product home page Git Product logo

Comments (7)

LauraGPT avatar LauraGPT commented on September 23, 2024

Maybe you could develop it with the doc.

from funasr.

taoqf avatar taoqf commented on September 23, 2024

I've tried send data, the most complicated part is splite data with nodejs.

from funasr.

taoqf avatar taoqf commented on September 23, 2024

I don't finger out how many bytes should I send per time. Even I send them all, I could not get answer from server, too. this is my test code.

async function connect(): Promise<WebSocket> {
	const uri = `wss://0.0.0.0:10095`;
	return new Promise<WebSocket>((resolve, reject) => {
		const ws = new WebSocket(uri, [], {
			rejectUnauthorized: false,
			// secureOptions: SSL_OP_NO_TLSv1_2,
		});
		ws.on('open', () => {
			console.log('连接成功');
			resolve(ws);
			setInterval(() => {
				ws.send('ping');
			}, 1000);
		});
		ws.on('message', (raw) => {
			const data = JSON.parse(Buffer.from(raw as Buffer).toString('utf-8')) as {
				text: string;
				timestamp: string;
				wav_name: string;
				is_final: boolean;
				mode: '2pass-offline';
				stamp_sents: {
					end: number;
					punc: string;
					start: number;
					text_seg: string;
					ts_list: number[];
				}[];
			};
			console.log('收到消息', data.text);
		});
		ws.on('error', (err) => {
			console.log('连接失败', err);
			reject(err);
		});
	});
}
async function main(): Promise<void> {
	const filepath = '/home/taoqf/Downloads/testmp4.wav';
	const mode = '2pass';
	// const mode = 'offline';
	const useItn = true;

	// 读取hotword文件并构建fst_dict
	const fstDict = {
		'产教': 10,
		// '铲掉': 0
	};
	const hotwordMessage = JSON.stringify(fstDict);
	console.log(hotwordMessage);

	const ws = await connect();
	console.log('开始发送数据');
	// 模拟sample_rate和wav_format
	const sampleRate = 8000; // 假设的采样率
	const wavFormat = 'pcm';
	const chunk_size = [5, 10, 5];	// 表示流式模型latency配置,`[5,10,5]`,表示当前音频为600ms,并且回看300ms,又看300ms。
	const chunk_interval = 10;

	// 发送第一条消息
	// {"audio_fs":8000,"chunk_interval":10,"chunk_size":[5,10,5],"hotwords":"","is_speaking":true,"itn":true,"mode":"offline","wav_format":"pcm","wav_name":"demo"}, msg_data->msg={"access_num":0,"audio_fs":8000,"is_eof":false,"itn":true,"mode":"offline","wav_format":"pcm","wav_name":"demo"}
	const message = JSON.stringify({
		mode,
		chunk_size,
		chunk_interval,
		audio_fs: sampleRate,
		wav_name: 'demo', // 假设的wav名称
		wav_format: wavFormat,
		is_speaking: true,
		hotwords: hotwordMessage,
		itn: useItn
	});
	await ws.send(message);
	// 处理wav文件
	const buf = await readFile(filepath);
	let i = 0;	 // skip first 44 wav header
	// ws.send(buf);
	const int_chunk_size = 60 * chunk_size[1] / chunk_interval;
	const chunk = sampleRate / 1000 * int_chunk_size;
	console.log('开始发送文件内容', buf.length, chunk);
	while (i < buf.length) {
		const sub = buf.subarray(i, i += chunk * 2);
		ws.send(sub);
		console.log('发送', i);
		await sleep(100);
	}
	console.log('文件内容发送结束');
	// await sleep(100000);
	// end 
	const endMessage = JSON.stringify({ is_speaking: false });
	await ws.send(endMessage);

	console.log('发送结束');

	// await ws.close();
	console.log('end');
}

from funasr.

taoqf avatar taoqf commented on September 23, 2024

@LauraGPT Could you please guid me? I really get into a dead end. I tried to call python client in nodejs, but I could only get results when the whole response is finished.

from funasr.

taoqf avatar taoqf commented on September 23, 2024

Is there anyone can help me?

from funasr.

LauraGPT avatar LauraGPT commented on September 23, 2024

@LauraGPT Could you please guid me? I really get into a dead end. I tried to call python client in nodejs, but I could only get results when the whole response is finished.

I do not have any skills about JS.

from funasr.

taoqf avatar taoqf commented on September 23, 2024

@LauraGPT Thank you anyway. btw, the doc need to be updated, there is no chunk param in the doc. but in fact, I could not send whole file to the server.

from funasr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.