import { AsrWsClient } from '../asr-ws-big-model-client.ts';

import { audioPath, config, sleep } from '../test/common.ts';

import net from 'net';
import { Recording } from '../../../../recorder/index.ts';
import Stream from 'stream';

const recorder = new Recording();

const asrClient = new AsrWsClient({
  appid: config.APP_ID,
  token: config.TOKEN,
});
// tsx src/asr/provider/volcengine/test/recorder.ts

const main = async () => {
  // await asrClient.sendVoiceFile(fs.readFileSync(audioPath));
  const send = (data: Buffer) => {
    asrClient.sendVoiceStream(data);
  };
  let chunks: Buffer = Buffer.alloc(0);
  var chunk_size = 960; // for asr chunk_size [5, 10, 5]
  let totalsend = 0;
  recorder.stream().on('data', (chunk) => {
    chunks = Buffer.concat([chunks, chunk]);
    const chunkSize = Buffer.byteLength(chunks);
    if (chunkSize > chunk_size) {
      send(chunks);
      totalsend += chunks.length;
      chunks = Buffer.alloc(0);
    }
  });
  // setTimeout(() => {
  //   recorder.stop();
  // }, 10000);
};

main();
