tikmp3/pkg.js

34 lines
953 B
JavaScript

const axios = require("axios");
const base = `https://api16-normal-useast5.us.tiktokv.com/media/api/text/speech/invoke/?text_speaker=`;
exports.get = async function(text, speaker) {
let s = (speaker || "en_us_001");
let u = `${base}${s}&req_text=${text.split(" ").join("+")}`;
let a = await axios.post(u);
let sc = a.data?.status_code;
if (sc == null || sc == 1) throw new Error((a.data?.status_msg??"An unknown error has occured"));
return Buffer.from(a.data.data.v_str, "base64");
}
exports.voices = function() {
// got list from here https://github.com/oscie57/tiktok-voice/blob/ffae2ca612968a6225958a798bf1603dd8c52990/main.py#L5
return [
"en_us_ghostface",
"en_us_chewbacca",
"en_us_c3po",
"en_us_stitch",
"en_us_rocket",
"en_us_002",
"en_us_006",
"en_au_001",
"en_au_002",
"en_uk_001",
"fr_001",
"fr_002",
"de_001",
"de_002",
"jp_001",
"je_003",
"es_002"
];
}