mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-17 13:57:10 +00:00
fix: azure语音云转码
This commit is contained in:
parent
2cafdcaa82
commit
1f50e1b7a5
1 changed files with 15 additions and 17 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
// import Contactable, { core } from 'oicq'
|
// import Contactable, { core } from 'oicq'
|
||||||
import querystring from 'querystring'
|
import querystring from 'querystring'
|
||||||
import fetch, { File, FormData } from 'node-fetch'
|
import fetch, { File, fileFromSync, FormData } from 'node-fetch'
|
||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
import os from 'os'
|
import os from 'os'
|
||||||
import util from 'util'
|
import util from 'util'
|
||||||
|
|
@ -36,11 +36,12 @@ async function uploadRecord (recordUrl) {
|
||||||
result = await getPttBuffer(recordUrl, Bot.config.ffmpeg_path)
|
result = await getPttBuffer(recordUrl, Bot.config.ffmpeg_path)
|
||||||
} else if (Config.cloudTranscode) {
|
} else if (Config.cloudTranscode) {
|
||||||
try {
|
try {
|
||||||
if (Config.cloudMode === 'buffer' || Config.cloudMode === 'file') {
|
if (Config.cloudMode === 'file') {
|
||||||
|
const formData = new FormData()
|
||||||
let buffer
|
let buffer
|
||||||
if (!recordUrl.startsWith('http')) {
|
if (!recordUrl.startsWith('http')) {
|
||||||
// 本地文件
|
// 本地文件
|
||||||
buffer = fs.readFileSync(recordUrl)
|
formData.append('file', fileFromSync(recordUrl))
|
||||||
} else {
|
} else {
|
||||||
let response = await fetch(recordUrl, {
|
let response = await fetch(recordUrl, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
|
|
@ -51,10 +52,8 @@ async function uploadRecord (recordUrl) {
|
||||||
const blob = await response.blob()
|
const blob = await response.blob()
|
||||||
const arrayBuffer = await blob.arrayBuffer()
|
const arrayBuffer = await blob.arrayBuffer()
|
||||||
buffer = Buffer.from(arrayBuffer)
|
buffer = Buffer.from(arrayBuffer)
|
||||||
}
|
|
||||||
if (Config.cloudMode === 'file') {
|
|
||||||
const formData = new FormData()
|
|
||||||
formData.append('file', new File([buffer], 'audio.wav'))
|
formData.append('file', new File([buffer], 'audio.wav'))
|
||||||
|
}
|
||||||
const resultres = await fetch(`${Config.cloudTranscode}/audio`, {
|
const resultres = await fetch(`${Config.cloudTranscode}/audio`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: formData
|
body: formData
|
||||||
|
|
@ -66,7 +65,6 @@ async function uploadRecord (recordUrl) {
|
||||||
logger.error(t)
|
logger.error(t)
|
||||||
throw e
|
throw e
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
const resultres = await fetch(`${Config.cloudTranscode}/audio`, {
|
const resultres = await fetch(`${Config.cloudTranscode}/audio`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue