We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
// utils/audioConverter.js import lamejs from "lamejs"; // var lamejs = require("lamejs");
// 确保全局变量已定义 window.MPEGMode = { STEREO: 0, JOINT_STEREO: 1, DUAL_CHANNEL: 2, SINGLE_CHANNEL: 3, };
export function wavToMp3(recorderData) { console.log("lamejs", lamejs); const channels = 1; // 单声道 const sampleRate = 16000; // 采样率 const kbps = 128; // 比特率
const mp3encoder = new lamejs.Mp3Encoder(channels, sampleRate, kbps); const mp3Data = []; const samples = new Int16Array(recorderData.buffer); // 从源中获取数据 const sampleBlockSize = 1152; // 576的倍数
for (let i = 0; i < samples.length; i += sampleBlockSize) { const sampleChunk = samples.subarray(i, i + sampleBlockSize); const mp3buf = mp3encoder.encodeBuffer(sampleChunk); if (mp3buf.length > 0) { mp3Data.push(mp3buf); } }
const mp3buf = mp3encoder.flush(); // 完成写入mp3 if (mp3buf.length > 0) { mp3Data.push(new Int8Array(mp3buf)); }
const blob = new Blob(mp3Data, { type: "audio/mp3" }); return blob; }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
// utils/audioConverter.js
import lamejs from "lamejs";
// var lamejs = require("lamejs");
// 确保全局变量已定义
window.MPEGMode = {
STEREO: 0,
JOINT_STEREO: 1,
DUAL_CHANNEL: 2,
SINGLE_CHANNEL: 3,
};
export function wavToMp3(recorderData) {
console.log("lamejs", lamejs);
const channels = 1; // 单声道
const sampleRate = 16000; // 采样率
const kbps = 128; // 比特率
const mp3encoder = new lamejs.Mp3Encoder(channels, sampleRate, kbps);
const mp3Data = [];
const samples = new Int16Array(recorderData.buffer); // 从源中获取数据
const sampleBlockSize = 1152; // 576的倍数
for (let i = 0; i < samples.length; i += sampleBlockSize) {
const sampleChunk = samples.subarray(i, i + sampleBlockSize);
const mp3buf = mp3encoder.encodeBuffer(sampleChunk);
if (mp3buf.length > 0) {
mp3Data.push(mp3buf);
}
}
const mp3buf = mp3encoder.flush(); // 完成写入mp3
if (mp3buf.length > 0) {
mp3Data.push(new Int8Array(mp3buf));
}
const blob = new Blob(mp3Data, { type: "audio/mp3" });
return blob;
}
The text was updated successfully, but these errors were encountered: