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

Function handleQuestionWithAudio

outdated/gemini/gemini.ts:1235–1329  ·  view source on GitHub ↗
(
  msg: Api.Message, 
  question: string, 
  displayQuestion: string,
  useSearch: boolean, 
  context: string,
  replyMsg?: Api.Message | null
)

Source from the content-addressed store, hash-verified

1233}
1234
1235async function handleQuestionWithAudio(
1236 msg: Api.Message,
1237 question: string,
1238 displayQuestion: string,
1239 useSearch: boolean,
1240 context: string,
1241 replyMsg?: Api.Message | null
1242): Promise<void> {
1243 try {
1244 const answer = await callGeminiChat(question, useSearch);
1245
1246 await msg.edit({ text: "🗣️ 转换为语音中..." });
1247
1248 const formattedText = formatResponse(displayQuestion, answer);
1249 const voiceName = ConfigManager.get(CONFIG_KEYS.GEMINI_TTS_VOICE, DEFAULT_CONFIG[CONFIG_KEYS.GEMINI_TTS_VOICE]);
1250 const searchText = useSearch ? ' with Google Search' : '';
1251
1252 try {
1253 const client = await getGeminiClient();
1254 const audioResponse = await client.generateTTS({
1255 model: getConfig(CONFIG_KEYS.GEMINI_TTS_MODEL),
1256 contents: [{ parts: [{ text: answer }] }],
1257 voiceName
1258 });
1259
1260 if (audioResponse.audioData?.length) {
1261 const combinedAudio = Buffer.concat(audioResponse.audioData);
1262
1263 if (combinedAudio.length > 0) {
1264
1265 if (replyMsg) {
1266 let processedAudio: any = combinedAudio;
1267
1268 if (audioResponse.audioMimeType && audioResponse.audioMimeType.includes('L16') && audioResponse.audioMimeType.includes('pcm')) {
1269 processedAudio = Utils.convertToWav(combinedAudio, audioResponse.audioMimeType) as any;
1270 }
1271
1272 const audioFile = Object.assign(processedAudio as any, {
1273 name: 'gemini.ogg'
1274 });
1275
1276 await msg.client?.sendFile(msg.peerId, {
1277 file: audioFile,
1278 caption: formattedText + `\n\n<i>Powered by Gemini${searchText} Audio (${voiceName})</i>`,
1279 parseMode: "html",
1280 replyTo: replyMsg.id,
1281 attributes: [new Api.DocumentAttributeAudio({
1282 duration: 0,
1283 voice: true
1284 })]
1285 });
1286
1287 try {
1288 await msg.delete();
1289 } catch {}
1290 } else {
1291 await Utils.sendAudioBuffer(
1292 msg,

Callers 2

handleAudioFunction · 0.85
handleSearchAudioFunction · 0.85

Calls 11

callGeminiChatFunction · 0.85
getGeminiClientFunction · 0.85
generateTTSMethod · 0.80
convertToWavMethod · 0.80
sendAudioBufferMethod · 0.80
formatResponseFunction · 0.70
getConfigFunction · 0.70
editMethod · 0.45
getMethod · 0.45
deleteMethod · 0.45
handleErrorMethod · 0.45

Tested by

no test coverage detected