mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
refactor: remove sample rate from silk encode
This commit is contained in:
parent
d1e4135442
commit
9aeb328952
@ -16,7 +16,6 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"express": "^4.18.2",
|
"express": "^4.18.2",
|
||||||
"fluent-ffmpeg": "^2.1.2",
|
"fluent-ffmpeg": "^2.1.2",
|
||||||
"music-metadata": "^8.1.4",
|
|
||||||
"silk-wasm": "^3.2.3",
|
"silk-wasm": "^3.2.3",
|
||||||
"utf-8-validate": "^6.0.3",
|
"utf-8-validate": "^6.0.3",
|
||||||
"uuid": "^9.0.1",
|
"uuid": "^9.0.1",
|
||||||
|
@ -178,17 +178,17 @@ export async function encodeSilk(filePath: string) {
|
|||||||
return isWav(fs.readFileSync(filePath));
|
return isWav(fs.readFileSync(filePath));
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getAudioSampleRate(filePath: string) {
|
// async function getAudioSampleRate(filePath: string) {
|
||||||
try {
|
// try {
|
||||||
const mm = await import('music-metadata');
|
// const mm = await import('music-metadata');
|
||||||
const metadata = await mm.parseFile(filePath);
|
// const metadata = await mm.parseFile(filePath);
|
||||||
log(`${filePath}采样率`, metadata.format.sampleRate);
|
// log(`${filePath}采样率`, metadata.format.sampleRate);
|
||||||
return metadata.format.sampleRate;
|
// return metadata.format.sampleRate;
|
||||||
} catch (error) {
|
// } catch (error) {
|
||||||
log(`${filePath}采样率获取失败`, error.stack);
|
// log(`${filePath}采样率获取失败`, error.stack);
|
||||||
// console.error(error);
|
// // console.error(error);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const fileName = path.basename(filePath);
|
const fileName = path.basename(filePath);
|
||||||
@ -219,9 +219,9 @@ export async function encodeSilk(filePath: string) {
|
|||||||
});
|
});
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
const sampleRate = await getAudioSampleRate(filePath) || 44100;
|
// const sampleRate = await getAudioSampleRate(filePath) || 0;
|
||||||
const pcm = fs.readFileSync(filePath);
|
const pcm = fs.readFileSync(filePath);
|
||||||
const silk = await encode(pcm, sampleRate);
|
const silk = await encode(pcm, 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