mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-16 13:27:08 +00:00
feat: add synthesis for api3
This commit is contained in:
parent
b76d33d938
commit
1f80758491
2 changed files with 39 additions and 0 deletions
|
|
@ -434,6 +434,14 @@ class Core {
|
|||
await redis.set(`CHATGPT:CONVERSATION_CREATER_ID:${sendMessageResult.conversationId}`, e.sender.user_id)
|
||||
await redis.set(`CHATGPT:CONVERSATION_CREATER_NICK_NAME:${sendMessageResult.conversationId}`, e.sender.card)
|
||||
}
|
||||
(async () => {
|
||||
let audio = await this.chatGPTApi.synthesis(sendMessageResult)
|
||||
if (audio) {
|
||||
await e.reply(segment.record(audio))
|
||||
}
|
||||
})().catch(err => {
|
||||
logger.warn('发送语音失败', err)
|
||||
})
|
||||
return sendMessageResult
|
||||
} else if (use === 'chatglm') {
|
||||
const cacheOptions = {
|
||||
|
|
|
|||
|
|
@ -164,4 +164,35 @@ export class OfficialChatGPTClient {
|
|||
return await this.sendMessage(prompt, opts, retry - 1)
|
||||
}
|
||||
}
|
||||
|
||||
voices = ['ember', 'cove',
|
||||
'juniper', 'sky', 'breeze'
|
||||
// '__internal_only_shimmer',
|
||||
// '__internal_only_santa'
|
||||
]
|
||||
|
||||
async synthesis (opts = {}) {
|
||||
const { messageId, conversationId } = opts
|
||||
let url = this._apiReverseUrl.replace('/conversation', '/synthesize')
|
||||
let randomVoice = this.voices[Math.floor(Math.random() * this.voices.length)]
|
||||
url = `${url}?message_id=${messageId}&conversation_id=${conversationId}?voice=${randomVoice}`
|
||||
let res = await fetch(url, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
accept: 'audio/mpeg',
|
||||
'x-openai-assistant-app-id': '',
|
||||
authorization: this._accessToken ? `Bearer ${this._accessToken}` : '',
|
||||
referer: 'https://chat.openai.com/chat',
|
||||
library: 'chatgpt-plugin'
|
||||
}
|
||||
})
|
||||
if (res.status !== 200) {
|
||||
throw new Error(await res.text())
|
||||
}
|
||||
if (res.headers.get('content-type') !== 'audio/mpeg') {
|
||||
throw new Error('invalid content type')
|
||||
}
|
||||
let buffer = await res.arrayBuffer()
|
||||
return Buffer.from(buffer)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue