mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-17 05:47:11 +00:00
feat: 支持转语音
This commit is contained in:
parent
5fc5d2e5aa
commit
6ed7588f27
4 changed files with 226 additions and 1 deletions
23
apps/chat.js
23
apps/chat.js
|
|
@ -12,6 +12,8 @@ import { KeyvFile } from 'keyv-file'
|
|||
import { OfficialChatGPTClient } from '../utils/message.js'
|
||||
import fetch from 'node-fetch'
|
||||
import { deleteConversation, getConversations, getLatestMessageIdByConversationId } from '../utils/conversation.js'
|
||||
import {convertSpeaker, generateAudio, speakers} from '../utils/tts.js'
|
||||
import { segment } from 'oicq'
|
||||
try {
|
||||
await import('keyv')
|
||||
} catch (err) {
|
||||
|
|
@ -352,6 +354,14 @@ export class chatgpt extends plugin {
|
|||
return false
|
||||
}
|
||||
}
|
||||
let useTTS = false
|
||||
let speaker = ''
|
||||
let trySplit = prompt.split('回答:')
|
||||
if (trySplit.length > 1 && speakers.indexOf(convertSpeaker(trySplit[0])) > -1) {
|
||||
useTTS = true
|
||||
speaker = convertSpeaker(trySplit[0])
|
||||
prompt = trySplit[1]
|
||||
}
|
||||
if (Config.imgOcr) {
|
||||
// 取消息中的图片、at的头像、回复的图片,放入e.img
|
||||
if (e.at && !e.source) {
|
||||
|
|
@ -543,7 +553,18 @@ export class chatgpt extends plugin {
|
|||
}
|
||||
})
|
||||
}
|
||||
if (userSetting.usePicture || (Config.autoUsePicture && response.length > Config.autoUsePictureThreshold)) {
|
||||
if (useTTS) {
|
||||
if (Config.ttsSpace) {
|
||||
let wav = await generateAudio(response, speaker, '中文')
|
||||
e.reply(segment.record(wav))
|
||||
} else {
|
||||
await this.reply('你没有配置转语音API哦,我用文本回复你吧', e.isGroup)
|
||||
await this.reply(`${response}`, e.isGroup)
|
||||
if (quotemessage.length > 0) {
|
||||
this.reply(await makeForwardMsg(this.e, quotemessage))
|
||||
}
|
||||
}
|
||||
} else if (userSetting.usePicture || (Config.autoUsePicture && response.length > Config.autoUsePictureThreshold)) {
|
||||
// todo use next api of chatgpt to complete incomplete respoonse
|
||||
try {
|
||||
await this.renderImage(e, use !== 'bing' ? 'content/ChatGPT/index' : 'content/Bing/index', response, prompt, quotemessage, Config.showQRCode)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue