MCPcopy Create free account
hub / github.com/TeleBoxOrg/TeleBox_Plugins / processAudioGeneration

Function processAudioGeneration

outdated/gemini/gemini.ts:1143–1215  ·  view source on GitHub ↗
(
msg: Api.Message, text: string, p0: string,
replyMsg?: Api.Message | null)

Source from the content-addressed store, hash-verified

1141}
1142
1143async function processAudioGeneration(
1144msg: Api.Message, text: string, p0: string,
1145replyMsg?: Api.Message | null): Promise<void> {
1146 const client = await getGeminiClient();
1147 const modelName = ConfigManager.get(CONFIG_KEYS.GEMINI_TTS_MODEL, DEFAULT_CONFIG[CONFIG_KEYS.GEMINI_TTS_MODEL]);
1148 const voiceName = ConfigManager.get(CONFIG_KEYS.GEMINI_TTS_VOICE, DEFAULT_CONFIG[CONFIG_KEYS.GEMINI_TTS_VOICE]);
1149
1150 const response = await client.generateTTS({
1151 model: modelName,
1152 contents: [{ parts: [{ text }] }],
1153 voiceName
1154 });
1155
1156 if (!response.audioData?.length) {
1157 throw new Error('没有收到音频数据');
1158 }
1159
1160 const combinedAudio = Buffer.concat(response.audioData);
1161 if (combinedAudio.length === 0) {
1162 throw new Error('合并后的音频数据为空');
1163 }
1164
1165 if (replyMsg) {
1166 let processedAudio: any = combinedAudio;
1167
1168 if (response.audioMimeType && response.audioMimeType.includes('L16') && response.audioMimeType.includes('pcm')) {
1169 processedAudio = Utils.convertToWav(combinedAudio, response.audioMimeType) as any;
1170 }
1171
1172 const audioFile = Object.assign(processedAudio as any, {
1173 name: 'gemini.ogg'
1174 });
1175
1176 await msg.client?.sendFile(msg.peerId, {
1177 file: audioFile,
1178 caption: `<b>文本:</b> ${Utils.escapeHtml(text)}\n\n<i>Powered by Gemini TTS (${voiceName})</i>`,
1179 parseMode: "html",
1180 replyTo: replyMsg.id,
1181 attributes: [new Api.DocumentAttributeAudio({
1182 duration: 0,
1183 voice: true
1184 })]
1185 });
1186
1187 try {
1188 await msg.delete();
1189 } catch {}
1190 } else {
1191 let processedAudio: any = combinedAudio;
1192
1193 if (response.audioMimeType && response.audioMimeType.includes('L16') && response.audioMimeType.includes('pcm')) {
1194 processedAudio = Utils.convertToWav(combinedAudio, response.audioMimeType) as any;
1195 }
1196
1197 const audioFile = Object.assign(processedAudio as any, {
1198 name: 'gemini.ogg'
1199 });
1200

Callers 1

handleTTSFunction · 0.85

Calls 6

getGeminiClientFunction · 0.85
generateTTSMethod · 0.80
convertToWavMethod · 0.80
escapeHtmlMethod · 0.80
getMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected