import { config } from './common.ts';
import { runDemo, TtsMix } from '../tts-mix.ts';
const appId = config.APP_ID;
const token = config.TOKEN;

// const speaker = 'zh_female_shuangkuaisisi_moon_bigtts';
const speaker = 'zh_female_roumeinvyou_emo_v2_mars_bigtts';
const text = '明朝开国皇帝朱元璋也称这本书为,万物之根';
const outputPath = 'videos/tts_mix.wav';
const text2 =
  '明朝开国皇帝朱元璋曾盛赞《道德经》为"万物之根"，认为这部道家经典蕴含着治国安邦的至理。这位出身寒微的帝王在建立大明王朝后，深刻体会到老子"无为而治"的智慧，将其奉为治国圭臬。朱元璋不仅亲自批注《道德经》，更命翰林学士编修《御注道德经》，将其中"治大国若烹小鲜"等思想运用于轻徭薄赋的惠民政策中';
// 按15个字分割文本为数组
const text2Arr = [];
for (let i = 0; i < text2.length; i += 2) {
  text2Arr.push(text2.slice(i, i + 2));
}
const sleep = async (ms = 1000) => {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve(true);
    }, ms);
  });
};
const mockSendText = (ttsMax: TtsMix) => {
  return new Promise(async (resolve, reject) => {
    for (let i = 0; i < text2Arr.length; i++) {
      const text = text2Arr[i];
      console.log('开始', i, text);
      ttsMax.emitter.emit('text', text);
      await sleep(10);
      // console.log('完成', i, text);
    }
    ttsMax.emitter.emit('textEnd');
  });
};
// tsx src/tts/provider/volcengine/test/mix.ts
const main = async () => {
  try {
    console.log('开始', appId, token);
    // await runDemo(appId, token, speaker, text, outputPath);
    const ttsMax = new TtsMix(appId, token);
    setTimeout(() => {
      mockSendText(ttsMax).then(() => {
        console.log('完成');
      });
    }, 10000);
    // await ttsMax.getVoiceDemo(speaker, text, outputPath);

    await ttsMax.getVoiceDemo(speaker, '', outputPath, false);
    console.log('完成');
  } catch (err) {
    console.log(err);
  }
};

main();
