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": {
|
||||
"express": "^4.18.2",
|
||||
"fluent-ffmpeg": "^2.1.2",
|
||||
"music-metadata": "^8.1.4",
|
||||
"silk-wasm": "^3.2.3",
|
||||
"utf-8-validate": "^6.0.3",
|
||||
"uuid": "^9.0.1",
|
||||
|
@ -178,17 +178,17 @@ export async function encodeSilk(filePath: string) {
|
||||
return isWav(fs.readFileSync(filePath));
|
||||
}
|
||||
|
||||
async function getAudioSampleRate(filePath: string) {
|
||||
try {
|
||||
const mm = await import('music-metadata');
|
||||
const metadata = await mm.parseFile(filePath);
|
||||
log(`${filePath}采样率`, metadata.format.sampleRate);
|
||||
return metadata.format.sampleRate;
|
||||
} catch (error) {
|
||||
log(`${filePath}采样率获取失败`, error.stack);
|
||||
// console.error(error);
|
||||
}
|
||||
}
|
||||
// async function getAudioSampleRate(filePath: string) {
|
||||
// try {
|
||||
// const mm = await import('music-metadata');
|
||||
// const metadata = await mm.parseFile(filePath);
|
||||
// log(`${filePath}采样率`, metadata.format.sampleRate);
|
||||
// return metadata.format.sampleRate;
|
||||
// } catch (error) {
|
||||
// log(`${filePath}采样率获取失败`, error.stack);
|
||||
// // console.error(error);
|
||||
// }
|
||||
// }
|
||||
|
||||
try {
|
||||
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 silk = await encode(pcm, sampleRate);
|
||||
const silk = await encode(pcm, 0);
|
||||
fs.writeFileSync(pttPath, silk.data);
|
||||
fs.unlink(wavPath, (err) => {
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user