Một mục mã nguồn mở trong kho dữ liệu GitHub của TopGit: ai/audio-recorder-polyfill, 589 sao, JavaScript. MediaRecorder polyfill to record audio in Edge and Safari
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
[!WARNING]
Deprecated: You do not need this polyfill for modern browsers
MediaRecorder polyfill to record audio in Edge and Safari.
Try it in online demo and see API.
Spec compatible. In the future when all browsers will support
MediaRecorder, you will remove polyfill.
Small. 1.11 KB (minified and gzipped). No dependencies.
It uses Size Limit to control size.
One file. In contrast to other recorders, this polyfill uses
“inline worker” and don’t need a separated file for Web Worker.
MP3 and WAV encoder support.
navigator.mediaDevices.getUserMedia({ audio: true }).then(stream => {
recorder = new MediaRecorder(stream)
recorder.addEventListener('dataavailable', e => {
audio.src = URL.createObjectURL(e.data)
})
recorder.start()
})
Install
Install package:
npm install --save audio-recorder-polyfill
We recommend creating separated webpack/Parcel bundle with polyfill.
In this case, polyfill will be downloaded only by Edge and Safari.
Good browsers will download less.
Files recorded without the polyfill will not be playable on Safari,
it is highly recommended to convert it to MP3 on the back-end
of your application. If that’s not an option you can use the polyfill
in all browsers to force the audio to be converted to the right format
with the price of client’s performance.
Polyfill supports ES modules. You do not need to do anything for bundlers.
For quick hacks you can load polyfill from CDN. Do not use it in production
because of low performance.
import AudioRecorder from 'https://cdn.jsdelivr.net/npm/audio-recorder-polyfill/index.js'
window.MediaRecorder = AudioRecorder
Usage
In the beginning, we need to show a warning in browsers without Web Audio API:
if (MediaRecorder.notSupported) {
noSupport.style.display = 'block'
dictaphone.style.display = 'none'
}
Then you can use standard MediaRecorder API:
let recorder
recordButton.addEventListener('click', () => {
// Request permissions to record audio
navigator.mediaDevices.getUserMedia({ audio: true }).then(stream => {
recorder = new MediaRecorder(stream)
// Set record to <audio> when recording will be finished
recorder.addEventListener('dataavailable', e => {
audio.src = URL.createObjectURL(e.data)
})
// Start recording
recorder.start()
})
})
stopButton.addEventListener('click', () => {
// Stop recording
recorder.stop()
// Remove “recording” icon from browser tab
recorder.stream.getTracks().forEach(i => i.stop())
})
If you need to upload record to the server, we recommend using timeslice.
MediaRecorder will send recorded data every specified millisecond.
So you will start uploading before recording would finish.
// Will be executed every second with next part of audio file
recorder.addEventListener('dataavailable', e => {
sendNextPiece(e.data)
})
// Dump audio data every second
recorder.start(1000)
Audio Formats
Chrome records natively only to .webm files. Firefox to .ogg.
You can get used file format in e.data.type:
recorder.addEventListener('dataavailable', e => {
e.data.type //=> 'audio/wav' with polyfill
// 'audio/webm' in Chrome
// 'audio/ogg' in Firefox
})
WAV
As default, this polyfill saves records to .wav files. Compression
is not very good, but encoding is fast and simple.
MP3
For better compression you may use the MP3 encoder.
import AudioRecorder from 'audio-recorder-polyfill'
import mpegEncoder from 'audio-recorder-polyfill/mpeg-encoder'
AudioRecorder.encoder = mpegEncoder
AudioRecorder.prototype.mimeType = 'audio/mpeg'
window.MediaRecorder = AudioRecorder
Limitations
This polyfill tries to be MediaRecorder API compatible.
But it still has small differences.
WAV format contains duration in the file header. As result, with timeslice
or requestData() call, dataavailable will receive a separated file
with header on every call. In contrast, MediaRecorder sends header only
to first dataavailable. Other events receive addition bytes
to the same file.
Constructor options are not supported.
BlobEvent.timecode is not supported.
Custom Encoder
If you need audio format with better compression,
you can change polyfill’s encoder:
ai/audio-recorder-polyfill có 589 sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/ai/audio-recorder-polyfill. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
ai/audio-recorder-polyfill có tag gì không?
Bản đồng bộ chưa ghi nhận topic GitHub nào cho ai/audio-recorder-polyfill. GitHub topics hiển thị ở thanh bên phải trang repo — đó là nơi đáng kiểm tra nhất.
ai/audio-recorder-polyfill còn đang phát triển không?
Commit gần nhất trên ai/audio-recorder-polyfill là 1.9 năm trước (theo timestamp GitHub). Repo có 77 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
ai/audio-recorder-polyfill là gì?
ai/audio-recorder-polyfill (ai/audio-recorder-polyfill) là dự án JavaScript trên GitHub. Theo mô tả gốc: MediaRecorder polyfill to record audio in Edge and Safari
ai/audio-recorder-polyfill viết bằng ngôn ngữ gì?
ai/audio-recorder-polyfill chủ yếu viết bằng JavaScript. Trường "language" của GitHub dựa trên phần lớn byte ở nhánh mặc định.
Đọc đầy đủ README ở tab phía trên.
Vẫn đang phân vân về audio-recorder-polyfill?
Một cú bấm sẽ gửi câu hỏi kèm trang này cho AI — xem AI nói gì về audio-recorder-polyfill.