mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
Merge branch 'main' into dev
This commit is contained in:
commit
48d62be2d6
8
package-lock.json
generated
8
package-lock.json
generated
@ -14,7 +14,7 @@
|
|||||||
"file-type": "^19.0.0",
|
"file-type": "^19.0.0",
|
||||||
"fluent-ffmpeg": "^2.1.2",
|
"fluent-ffmpeg": "^2.1.2",
|
||||||
"level": "^8.0.1",
|
"level": "^8.0.1",
|
||||||
"silk-wasm": "^3.2.4",
|
"silk-wasm": "^3.3.2",
|
||||||
"utf-8-validate": "^6.0.3",
|
"utf-8-validate": "^6.0.3",
|
||||||
"uuid": "^9.0.1",
|
"uuid": "^9.0.1",
|
||||||
"ws": "^8.16.0"
|
"ws": "^8.16.0"
|
||||||
@ -5895,9 +5895,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/silk-wasm": {
|
"node_modules/silk-wasm": {
|
||||||
"version": "3.2.4",
|
"version": "3.3.2",
|
||||||
"resolved": "https://registry.npmjs.org/silk-wasm/-/silk-wasm-3.2.4.tgz",
|
"resolved": "https://registry.npmjs.org/silk-wasm/-/silk-wasm-3.3.2.tgz",
|
||||||
"integrity": "sha512-oBkXmdIRl7cyzpoXEeEVN7v1M2yCnH1/bN8oANoYTvCqbYa5lM/CGJP47DYbpUFVO9PUpm58KP/HZaVzt4J6jw=="
|
"integrity": "sha512-CXG/hikSInuI/A+EIPoq+z1BRv4SJdhIQKtscOiwZS3udSOr+4DBPYmqNtlV3AKldjEhJChIRCsBtWcWRe54ng=="
|
||||||
},
|
},
|
||||||
"node_modules/slash": {
|
"node_modules/slash": {
|
||||||
"version": "4.0.0",
|
"version": "4.0.0",
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
"file-type": "^19.0.0",
|
"file-type": "^19.0.0",
|
||||||
"fluent-ffmpeg": "^2.1.2",
|
"fluent-ffmpeg": "^2.1.2",
|
||||||
"level": "^8.0.1",
|
"level": "^8.0.1",
|
||||||
"silk-wasm": "^3.2.4",
|
"silk-wasm": "^3.3.2",
|
||||||
"utf-8-validate": "^6.0.3",
|
"utf-8-validate": "^6.0.3",
|
||||||
"uuid": "^9.0.1",
|
"uuid": "^9.0.1",
|
||||||
"ws": "^8.16.0"
|
"ws": "^8.16.0"
|
||||||
|
@ -3,7 +3,7 @@ import fsPromise from "fs/promises";
|
|||||||
import crypto from "crypto";
|
import crypto from "crypto";
|
||||||
import ffmpeg from "fluent-ffmpeg";
|
import ffmpeg from "fluent-ffmpeg";
|
||||||
import util from "util";
|
import util from "util";
|
||||||
import {encode, getDuration, isWav} from "silk-wasm";
|
import {encode, getDuration, isWav, getWavFileInfo} from "silk-wasm";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import {v4 as uuidv4} from "uuid";
|
import {v4 as uuidv4} from "uuid";
|
||||||
import {checkFfmpeg, DATA_DIR, log, TEMP_DIR} from "./index";
|
import {checkFfmpeg, DATA_DIR, log, TEMP_DIR} from "./index";
|
||||||
@ -126,10 +126,8 @@ export async function encodeSilk(filePath: string) {
|
|||||||
log(`语音文件${filePath}需要转换成silk`)
|
log(`语音文件${filePath}需要转换成silk`)
|
||||||
const _isWav = await isWavFile(filePath);
|
const _isWav = await isWavFile(filePath);
|
||||||
const wavPath = pttPath + ".wav"
|
const wavPath = pttPath + ".wav"
|
||||||
if (!_isWav) {
|
const convert = async () => {
|
||||||
log(`语音文件${filePath}正在转换成wav`)
|
return await new Promise((resolve, reject) => {
|
||||||
// let voiceData = await fsp.readFile(filePath)
|
|
||||||
await new Promise((resolve, reject) => {
|
|
||||||
const ffmpegPath = getConfigUtil().getConfig().ffmpeg;
|
const ffmpegPath = getConfigUtil().getConfig().ffmpeg;
|
||||||
if (ffmpegPath) {
|
if (ffmpegPath) {
|
||||||
ffmpeg.setFfmpegPath(ffmpegPath);
|
ffmpeg.setFfmpegPath(ffmpegPath);
|
||||||
@ -148,10 +146,21 @@ export async function encodeSilk(filePath: string) {
|
|||||||
});
|
});
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
// const sampleRate = await getAudioSampleRate(filePath) || 0;
|
let wav: Buffer
|
||||||
// log("音频采样率", sampleRate)
|
if (!_isWav) {
|
||||||
const pcm = fs.readFileSync(filePath);
|
log(`语音文件${filePath}正在转换成wav`)
|
||||||
const silk = await encode(pcm, 0);
|
await convert()
|
||||||
|
} else {
|
||||||
|
wav = fs.readFileSync(filePath)
|
||||||
|
const allowSampleRate = [8000, 12000, 16000, 24000, 32000, 44100, 48000]
|
||||||
|
const { fmt } = getWavFileInfo(wav)
|
||||||
|
if (!allowSampleRate.includes(fmt.sampleRate)) {
|
||||||
|
wav = undefined
|
||||||
|
await convert()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
wav ||= fs.readFileSync(filePath);
|
||||||
|
const silk = await encode(wav, 0);
|
||||||
fs.writeFileSync(pttPath, silk.data);
|
fs.writeFileSync(pttPath, silk.data);
|
||||||
fs.unlink(wavPath, (err) => {
|
fs.unlink(wavPath, (err) => {
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user