This package is hugely inspired by kook-voice-API

在使用此软件包之前,您需要确认您理解,通过使用此软件包,您正在违反

  • 《KOOK 软件许可及服务协议》中 3.2.3 或 3.2.5 节
  • 《KOOK 开发者隐私协议》中 “数据信息” 或 “滥用” 部分

您的 KOOK 账号可能面临惩罚,包括但不限于

  • 对开发者工具与资源访问的限制
  • 对用户账号停权

您在使用本软件包时,风险自负。不提供任何保证


import koice from 'koice';

您必须将 ffmpeg 加入至 PATH。或您可手动指定一个

const client = new koice('Your KOOK bot token', '/path/to/your/ffmpeg/binary');

建立 WebSocket 链接并获取 RTP URL

client.connectWebSocket("8403799012661514");

使用文件的路径或一个 stream.readable 开始串流

import * as fs from 'fs';
const stream = fs.createReadStream('/path/to/music/file');
await client.startStream(stream);

await client.startStream('/path/to/music/file');

您也可以建立一个 ZeroMQ 服务器,以能够在不断开链接的情况下串流不同的文件。您可以这样做,通过先唤起 koice.startServer() ,再开始串流。

await client.startServer();
await client.startStream('/path/to/music/file');

您也可以关闭 ZeroMQ 服务器,但不停止串流,以在无需重新串流的情况下切换语音频道。

import * as fs from 'fs';
const stream = fs.createReadStream('/path/to/music/file');
client.connectWebSocket("8591468140337193");
await client.startServer();
await client.startStream(stream);
await delay(1000);
await client.closeServer();
await client.disconnectWebSocket();
client.connectWebSocket("1586400722913705");
await client.startServer();

您可以参考 kook-ongaku-play 作为一个真实应用样例。


© 2022 Hexona, koice.js and kook-ongaku-play, 在 MIT 许可下释出。


Before using this package, you confirm you understand by using this package, you are violating

Your KOOK account could face penalty including, but not limited to,

  • restriction to the access of developer tools and resources
  • suspension of user account

Use this package at your own risk. No warranties are provided.


import koice from 'koice';

You must have ffmpeg in your PATH, or you can specify one

const client = new koice('Your KOOK bot token', '/path/to/your/ffmpeg/binary');

Connect to WebSocket and retrive RTP URL.

client.connectWebSocket("8403799012661514");

Start streaming with path to a file or a stream.readable ;

import * as fs from 'fs';
const stream = fs.createReadStream('/path/to/music/file');
await client.startStream(stream);

or

await client.startStream('/path/to/music/file');

You can also start a ZeroMQ server to be able to stream different files without disconnecting. You can do that by invoking koice.startServer() first, then start streaming.

await client.startServer();
await client.startStream('/path/to/music/file');

And you can also close the ZeroMQ server without stopping the stream, to switch voice channel without streaming again.

import * as fs from 'fs';
const stream = fs.createReadStream('/path/to/music/file');
client.connectWebSocket("8591468140337193");
await client.startServer();
await client.startStream(stream);
await delay(1000);
await client.closeServer();
await client.disconnectWebSocket();
client.connectWebSocket("1586400722913705");
await client.startServer();

You can refer to kook-ongaku-play for usage of this package in real world application.


© 2022 Hexona, koice.js and kook-ongaku-play, released under the MIT license.

更新于 阅读次数

请我喝[茶]~( ̄▽ ̄)~*

saltcute 微信支付

微信支付

saltcute 支付宝

支付宝

saltcute 贝宝

贝宝