24-audio 中文文档教程
24-audio
记录你的麦克风音频输入,最后得到一个 audio/mp3
文件。 该项目是对 mic-recorder-to-mp3 的补充。 (修复与 safri 浏览器的兼容性问题。)
Install
npm
npm install 24-audio
How to use
const MicRecorder = require('24-audio');
// New instance
const recorder = new MicRecorder({
bitRate: 128
});
// Start recording. Browser will request permission to use your microphone.
recorder.start().then(() => {
// something else
}).catch((e) => {
console.error(e);
});
// Once you are done singing your best song, stop and get the mp3.
recorder
.stop()
.getMp3().then(([buffer, blob]) => {
// do what ever you want with buffer and blob
// Example: Create a mp3 file and play
const file = new File(buffer, 'me-at-thevoice.mp3', {
type: blob.type,
lastModified: Date.now()
});
const player = new Audio(URL.createObjectURL(file));
player.play();
}).catch((e) => {
alert('We could not retrieve your message');
console.log(e);
});
Lamejs Notice
这个库使用 lamejs 作为直接依赖项。 我们使用内置的 lamejs 构建我们的版本,因此您无需添加其他依赖项。
感谢 @zhuker 编写了 lamejs 库。
这个项目是对 mic-recorder-to-mp3
License
MIT的补充
24-audio
Record your microphone audio input and get an audio/mp3
file in the end. This project is supplementary to the mic-recorder-to-mp3 . (Fix compatibility issues with safri browsers.)
Install
npm
npm install 24-audio
How to use
const MicRecorder = require('24-audio');
// New instance
const recorder = new MicRecorder({
bitRate: 128
});
// Start recording. Browser will request permission to use your microphone.
recorder.start().then(() => {
// something else
}).catch((e) => {
console.error(e);
});
// Once you are done singing your best song, stop and get the mp3.
recorder
.stop()
.getMp3().then(([buffer, blob]) => {
// do what ever you want with buffer and blob
// Example: Create a mp3 file and play
const file = new File(buffer, 'me-at-thevoice.mp3', {
type: blob.type,
lastModified: Date.now()
});
const player = new Audio(URL.createObjectURL(file));
player.play();
}).catch((e) => {
alert('We could not retrieve your message');
console.log(e);
});
Lamejs Notice
This library uses lamejs as a direct dependency. We build our releases with lamejs built-in, so you don't need to add another dependency.
Thanks to @zhuker for writing the lamejs library.
This project is supplementary to the mic-recorder-to-mp3
License
MIT
更多