mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
commit
2f87e3818e
@ -23,7 +23,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.3.4",
|
"silk-wasm": "^3.6.0",
|
||||||
"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"
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
import fsAsync from 'fs/promises'
|
import fsAsync from 'fs/promises'
|
||||||
import fsPromise from 'fs/promises'
|
import fsPromise from 'fs/promises'
|
||||||
import { decode, encode, getDuration, getWavFileInfo, isWav } from 'silk-wasm'
|
import { decode, encode, getDuration, getWavFileInfo, isWav, isSilk } from 'silk-wasm'
|
||||||
import { log } from './log'
|
import { log } from './log'
|
||||||
import path from 'node:path'
|
import path from 'node:path'
|
||||||
import { TEMP_DIR } from './index'
|
import { TEMP_DIR } from './index'
|
||||||
@ -61,10 +61,11 @@ export async function encodeSilk(filePath: string) {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const file = await fsPromise.readFile(filePath)
|
||||||
const pttPath = path.join(TEMP_DIR, uuidv4())
|
const pttPath = path.join(TEMP_DIR, uuidv4())
|
||||||
if (getFileHeader(filePath) !== '02232153494c4b') {
|
if (!isSilk(file)) {
|
||||||
log(`语音文件${filePath}需要转换成silk`)
|
log(`语音文件${filePath}需要转换成silk`)
|
||||||
const _isWav = await isWavFile(filePath)
|
const _isWav = isWav(file)
|
||||||
const pcmPath = pttPath + '.pcm'
|
const pcmPath = pttPath + '.pcm'
|
||||||
let sampleRate = 0
|
let sampleRate = 0
|
||||||
const convert = () => {
|
const convert = () => {
|
||||||
@ -93,7 +94,7 @@ export async function encodeSilk(filePath: string) {
|
|||||||
if (!_isWav) {
|
if (!_isWav) {
|
||||||
input = await convert()
|
input = await convert()
|
||||||
} else {
|
} else {
|
||||||
input = fs.readFileSync(filePath)
|
input = file
|
||||||
const allowSampleRate = [8000, 12000, 16000, 24000, 32000, 44100, 48000]
|
const allowSampleRate = [8000, 12000, 16000, 24000, 32000, 44100, 48000]
|
||||||
const { fmt } = getWavFileInfo(input)
|
const { fmt } = getWavFileInfo(input)
|
||||||
// log(`wav文件信息`, fmt)
|
// log(`wav文件信息`, fmt)
|
||||||
@ -110,7 +111,7 @@ export async function encodeSilk(filePath: string) {
|
|||||||
duration: silk.duration / 1000,
|
duration: silk.duration / 1000,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const silk = fs.readFileSync(filePath)
|
const silk = file
|
||||||
let duration = 0
|
let duration = 0
|
||||||
try {
|
try {
|
||||||
duration = getDuration(silk) / 1000
|
duration = getDuration(silk) / 1000
|
||||||
|
Loading…
x
Reference in New Issue
Block a user