coze-plugin-utils
Version:
Comprehensive utility library for Coze plugins with multimedia processing, browser automation, cloud storage integration, and AI-powered video/audio generation capabilities
56 lines • 1.94 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.tts = tts;
const node_path_1 = __importDefault(require("node:path"));
const promises_1 = __importDefault(require("node:fs/promises"));
const core_1 = require("../core");
async function tts({ model, voiceName, text, speed = 1.0, pitch = 0, volumn = 1.0, emotion = 'neutral', }) {
const config = (0, core_1.getGlobalConfig)('minimax');
if (!config) {
throw new Error('请先配置minimax');
}
const api = `https://api.minimaxi.com/v1/t2a_v2?GroupId=${config.groupId}`;
const headers = {
'Content-Type': 'application/json',
'Authorization': `Bearer ${config.apiKey}`,
};
const payload = {
model,
text,
stream: false,
voice_setting: {
voice_id: voiceName,
speed,
pitch,
vol: volumn,
emotion,
},
pronunciation_dict: {
tone: ['处理/(chu3)(li3)', '危险/dangerous'],
},
audio_setting: {
sample_rate: 32000,
bitrate: 128000,
format: 'mp3',
channel: 1,
},
};
// console.log(api, payload);
const res = await fetch(api, {
method: 'POST',
headers,
body: JSON.stringify(payload),
});
if (!res.ok) {
throw new Error(`请求失败: ${res.status}`);
}
const { data, extra_info } = await res.json();
const tmpDir = await (0, core_1.createTempDir)();
const audioPath = node_path_1.default.join(tmpDir, 'speech.mp3');
await promises_1.default.writeFile(audioPath, Buffer.from(data.audio, 'hex'));
return { audio: audioPath, duration: extra_info.audio_length / 1000 };
}
//# sourceMappingURL=minimax.speech.js.map