• Stars
    star
    337
  • Rank 120,658 (Top 3 %)
  • Language
    JavaScript
  • License
    Creative Commons ...
  • Created about 6 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🎡 Library for creating voice messages

vmsg npm

vmsg is a small library for creating voice messages. While traditional way of communicating on the web is via text, sometimes it's easier or rather funnier to express your thoughts just by saying it. Of course it doesn't require any special support: record your voice with some standard program, upload to file hosting and share the link. But why bother with all of that tedious stuff if you can do the same in browser with a few clicks.

🎊 πŸŽ‰ DEMO πŸŽ‰ 🎊

Features

  • No dependencies, framework-agnostic, can be easily added to any site
  • Small: ~73kb gzipped WASM module and ~3kb gzipped JS + CSS
  • Uses MP3 format which is widely supported
  • Works in all latest browsers

Supported browsers

  • Chrome 32+
  • Firefox 27+
  • Safari 11+
  • Edge 12+

Usage

npm install vmsg --save
import { record } from "vmsg";

someButton.onclick = function() {
  record(/* {wasmURL: "/static/js/vmsg.wasm"} */).then(blob => {
    console.log("Recorded MP3", blob);
    // Can be used like this:
    //
    // const form = new FormData();
    // form.append("file[]", blob, "record.mp3");
    // fetch("/upload.php", {
    //   credentials: "include",
    //   method: "POST",
    //   body: form,
    // }).then(resp => {
    // });
  });
};

That's it! Don't forget to include vmsg.css and vmsg.wasm in your project. For browsers without WebAssembly support you need to also include wasm-polyfill.js.

See demo directory for a more feasible example.

A minimal React example for using Recorder with your own UI can be found here.

See also non React demo and Recording mp3 audio in HTML5 using vmsg article.

Development

  1. Install Emscripten SDK.
  2. Install latest LLVM, Clang and LLD with WebAssembly backend, fix LLVM_ROOT variable of Emscripten config.
  3. Make sure you have a standard GNU development environment.
  4. Activate emsdk environment.
  5. git clone --recurse-submodules https://github.com/Kagami/vmsg.git && cd vmsg
    make clean all
    npm install
    npm start

These instructions are very basic because there're a lot of systems with different conventions. Docker image would probably be provided to fix it.

Technical details for nerds

vmsg uses LAME encoder underneath compiled with Emscripten to WebAssembly module. LAME build is optimized for size, weights only little more than 70kb gzipped and can be super-efficiently fetched and parsed by browser. It's like a small image.

Access to microphone is implemented with Web Audio API, data samples sent to Web Worker which is responsibe for loading WebAssembly module and calling LAME API.

Module is produced with modern LLVM WASM backend and LLD linker which should become standard soon, also vmsg has own tiny WASM runtime instead of Emscripten's to decrease overall size and simplify architecture. Worker code is included in the main JS module so end-user has to care only about 3 files: vmsg.js, vmsg.css and vmsg.wasm. CSS can be inlined too but IMO that would be ugly.

In order to support browsers without WebAssembly, WebAssembly polyfill is being used. It translates binary module into semantically-equivalent JavaScript on the fly (almost asm.js compatible but doesn't fully validate yet) so we don't need separate asm.js build and can use standard WebAssembly API. It's not as effecient but for audio encoding should be enough.

See also: Creating WebAssembly-powered library for modern web article.

Why not MediaRecorder?

MediaStream Recording API is great but:

  • Works only in Firefox and Chrome
  • Provides little to no options, e.g. VBR quality can't be specified
  • Firefox/Chrome encode only to Opus which can't be natively played in Safari and Edge

But you can use e.g. ogv.js polyfill!

  • It make things more complicated, now you need both encoder and decoder
  • Opus gives you ~2x bitrate win but for 500kb per minute files it's not that much
  • MP3 is much more widespread, so even while compression is not best compatibility matters

License

vmsg is licensed under CC0.
LAME is licensed under LGPL.
MP3 patents seems to have expired since April 23, 2017.

More Repositories

1

ffmpeg.js

Port of FFmpeg with Emscripten
JavaScript
3,160
star
2

go-face

πŸ” Face recognition with Go
Go
1,052
star
3

avif.js

:shipit: AVIF polyfill for the browser
JavaScript
662
star
4

webm.js

JavaScript WebM converter
JavaScript
452
star
5

boram

🎞️ Cross-platform graphical WebM converter
JavaScript
428
star
6

mpv.js

πŸŽ₯ mpv pepper plugin
C++
395
star
7

go-avif

🎨 Go AVIF library
Go
304
star
8

gulp-ng-annotate

πŸ“Œ Add angularjs dependency injection annotations with ng-annotate
JavaScript
265
star
9

webm.py

🎞️ Cross-platform command-line WebM converter
Python
142
star
10

chaptcha

Break 2ch CAPTCHA using OpenCV and FANN
Python
85
star
11

mpv_slicing

Cut video fragments with mpv
Lua
76
star
12

wybm

βœ‚οΈ Extract and cut youtube webms
JavaScript
56
star
13

dav1d.js

βš—οΈ WebAssembly AV1 decoder
C
31
star
14

tistore

πŸ“· Tistory photo grabber
JavaScript
23
star
15

kagome

Application cage
Shell
19
star
16

mpv_frame_info

Show frame info with mpv
Lua
16
star
17

go-face-testdata

πŸ—ƒοΈ Test data for go-face
14
star
18

github-social-graph

Build simple social graphs for GitHub
Python
14
star
19

video-tools

Various video tools
Jupyter Notebook
13
star
20

kisa

XMPP stress tool
Python
13
star
21

bnw-meow

Kawaii single-page web interface for BnW
CoffeeScript
11
star
22

docker_cve-2015-2925

Docker + CVE-2015-2925 = escaping from --volume
10
star
23

nacl_sdk

🍴 Fork of Native Client SDK
Python
9
star
24

wasm-polyfill.js

🍴 Fork of rfk's project
JavaScript
9
star
25

av1-bench

🏎️ AV1 encoders benchmarks
Python
8
star
26

dotfiles

Dotfiles the easy way
Vim Script
6
star
27

jade-pages-brunch

Adds Jade static pages support to brunch
CoffeeScript
6
star
28

kpopnet

[MOVED]
Go
6
star
29

ng-annotate-uglify-js-brunch

Adds ng-annotate AND UglifyJS support to brunch
JavaScript
4
star
30

SVT-AV1

🍴 Welcome to the GitHub repo for the SVT-AV1 encoder! To see a list of feature request and view what is planned for the SVT-AV1 encoder, visit our Trello page: bit.ly/SVT-AV1 Help us grow the community by subscribing to our SVT-AV1 mailing list! http://bit.ly/svt-av1-mailing
C
4
star
31

jade-ngtemplates-brunch

Adds Jade AngularJS templates support to brunch
CoffeeScript
3
star
32

awesome-cloud-cli

A curated list of useful CLI tools for cloud hostings
JavaScript
3
star
33

hangeul.js

πŸ‡°πŸ‡· Hangeul transliteration library
JavaScript
2
star
34

cirno

(OBSOLETE) Dumb XMPP library, the successor of the XMPP lib
Haskell
2
star
35

dogfood

πŸ”© Basic blocks of operating system
C
2
star
36

parcel-plugin-disable-loaders

πŸ“¦ Allow to disable parcel loaders
JavaScript
2
star
37

webmify

Allow to watch WebMs in Edge
JavaScript
2
star
38

web-bench

Benchmarks for various web platforms
Perl
2
star
39

ninnin

🎞️ mpv-based video encoding tool
TypeScript
2
star
40

shitsu

Tiny and flexible XMPP bot framework
Python
2
star
41

skip-loader

A loader that returns an empty string module
JavaScript
1
star
42

lame-svn

Git mirror
C
1
star
43

gulp-recipes

Tiny gulp recipes
1
star