mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
Merge branch 'main' into dev
# Conflicts: # src/common/utils/file.ts
This commit is contained in:
commit
175a8ceb3d
8
package-lock.json
generated
8
package-lock.json
generated
@ -14,7 +14,7 @@
|
||||
"file-type": "^19.0.0",
|
||||
"fluent-ffmpeg": "^2.1.2",
|
||||
"level": "^8.0.1",
|
||||
"silk-wasm": "^3.2.3",
|
||||
"silk-wasm": "^3.2.4",
|
||||
"utf-8-validate": "^6.0.3",
|
||||
"uuid": "^9.0.1",
|
||||
"ws": "^8.16.0"
|
||||
@ -5895,9 +5895,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/silk-wasm": {
|
||||
"version": "3.2.3",
|
||||
"resolved": "https://registry.npmjs.org/silk-wasm/-/silk-wasm-3.2.3.tgz",
|
||||
"integrity": "sha512-zZ3hgMpiPR6cFnKvCPgPpCwx6n5RoJCbEGIFlge2kAxAmgzBTf0b2F2xIPG5W4obUhQPQXXTTH074eGZJK01xw=="
|
||||
"version": "3.2.4",
|
||||
"resolved": "https://registry.npmjs.org/silk-wasm/-/silk-wasm-3.2.4.tgz",
|
||||
"integrity": "sha512-oBkXmdIRl7cyzpoXEeEVN7v1M2yCnH1/bN8oANoYTvCqbYa5lM/CGJP47DYbpUFVO9PUpm58KP/HZaVzt4J6jw=="
|
||||
},
|
||||
"node_modules/slash": {
|
||||
"version": "4.0.0",
|
||||
|
@ -19,7 +19,7 @@
|
||||
"file-type": "^19.0.0",
|
||||
"fluent-ffmpeg": "^2.1.2",
|
||||
"level": "^8.0.1",
|
||||
"silk-wasm": "^3.2.3",
|
||||
"silk-wasm": "^3.2.4",
|
||||
"utf-8-validate": "^6.0.3",
|
||||
"uuid": "^9.0.1",
|
||||
"ws": "^8.16.0"
|
||||
|
@ -11,6 +11,7 @@ import {getConfigUtil} from "../config";
|
||||
import {dbUtil} from "../db";
|
||||
import * as fileType from "file-type";
|
||||
import {net} from "electron";
|
||||
import config from "../../../electron.vite.config";
|
||||
|
||||
|
||||
export function isGIF(path: string) {
|
||||
@ -67,6 +68,8 @@ export async function file2base64(path: string) {
|
||||
}
|
||||
|
||||
export async function encodeSilk(filePath: string) {
|
||||
const fsp = require("fs").promises
|
||||
|
||||
function getFileHeader(filePath: string) {
|
||||
// 定义要读取的字节数
|
||||
const bytesToRead = 7;
|
||||
@ -129,7 +132,7 @@ export async function encodeSilk(filePath: string) {
|
||||
if (ffmpegPath) {
|
||||
ffmpeg.setFfmpegPath(ffmpegPath);
|
||||
}
|
||||
ffmpeg(filePath).toFormat("wav").audioChannels(2).on('end', function () {
|
||||
ffmpeg(filePath).toFormat("wav").audioChannels(1).audioFrequency(24000).on('end', function () {
|
||||
log('wav转换完成');
|
||||
})
|
||||
.on('error', function (err) {
|
||||
@ -146,21 +149,22 @@ export async function encodeSilk(filePath: string) {
|
||||
// const sampleRate = await getAudioSampleRate(filePath) || 0;
|
||||
// log("音频采样率", sampleRate)
|
||||
const pcm = fs.readFileSync(filePath);
|
||||
let silk = await encode(pcm, 0);
|
||||
const silk = await encode(pcm, 0);
|
||||
fs.writeFileSync(pttPath, silk.data);
|
||||
fs.unlink(wavPath, (err) => {
|
||||
});
|
||||
const duration = verifyDuration(silk.duration / 1000, await guessDuration(filePath))
|
||||
log(`语音文件${filePath}转换成功!`, pttPath, `时长:`, silk.duration)
|
||||
return {
|
||||
converted: true,
|
||||
path: pttPath,
|
||||
duration
|
||||
duration: silk.duration,
|
||||
};
|
||||
} else {
|
||||
const pcm = fs.readFileSync(filePath);
|
||||
const silk = fs.readFileSync(filePath);
|
||||
let duration = 0;
|
||||
const gDuration = await guessDuration(filePath)
|
||||
try {
|
||||
duration = getDuration(silk);
|
||||
duration = verifyDuration(getDuration(pcm), gDuration);
|
||||
} catch (e) {
|
||||
log("获取语音文件时长失败, 使用文件大小推测时长", filePath, e.stack)
|
||||
|
Loading…
x
Reference in New Issue
Block a user