• Stars
    star
    348
  • Rank 121,840 (Top 3 %)
  • Language
    JavaScript
  • License
    Creative Commons ...
  • Created over 6 years ago
  • Updated over 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,299
star
2

go-face

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

avif.js

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

webm.js

JavaScript WebM converter
JavaScript
456
star
5

boram

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

mpv.js

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

go-avif

🎨 Go AVIF library
Go
323
star
8

gulp-ng-annotate

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

webm.py

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

chaptcha

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

mpv_slicing

Cut video fragments with mpv
Lua
82
star
12

wybm

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

dav1d.js

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

tistore

πŸ“· Tistory photo grabber
JavaScript
24
star
15

kagome

Application cage
Shell
19
star
16

mpv_frame_info

Show frame info with mpv
Lua
18
star
17

video-tools

Various video tools
Jupyter Notebook
16
star
18

go-face-testdata

πŸ—ƒοΈ Test data for go-face
15
star
19

github-social-graph

Build simple social graphs for GitHub
Python
15
star
20

kisa

XMPP stress tool
Python
14
star
21

docker_cve-2015-2925

Docker + CVE-2015-2925 = escaping from --volume
11
star
22

wasm-polyfill.js

🍴 Fork of rfk's project
JavaScript
11
star
23

bnw-meow

Kawaii single-page web interface for BnW
CoffeeScript
10
star
24

nacl_sdk

🍴 Fork of Native Client SDK
Python
10
star
25

av1-bench

🏎️ AV1 encoders benchmarks
Python
9
star
26

dotfiles

Dotfiles the easy way
Vim Script
7
star
27

jade-pages-brunch

Adds Jade static pages support to brunch
CoffeeScript
7
star
28

kpopnet

[MOVED]
Go
7
star
29

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
7
star
30

ng-annotate-uglify-js-brunch

Adds ng-annotate AND UglifyJS support to brunch
JavaScript
5
star
31

jade-ngtemplates-brunch

Adds Jade AngularJS templates support to brunch
CoffeeScript
4
star
32

awesome-cloud-cli

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

ninnin

🎞️ mpv-based video encoding tool
TypeScript
4
star
34

hangeul.js

πŸ‡°πŸ‡· Hangeul transliteration library
JavaScript
3
star
35

cirno

(OBSOLETE) Dumb XMPP library, the successor of the XMPP lib
Haskell
3
star
36

dogfood

πŸ”© Basic blocks of operating system
C
3
star
37

webmify

Allow to watch WebMs in Edge
JavaScript
3
star
38

web-bench

Benchmarks for various web platforms
Perl
3
star
39

parcel-plugin-disable-loaders

πŸ“¦ Allow to disable parcel loaders
JavaScript
3
star
40

shitsu

Tiny and flexible XMPP bot framework
Python
3
star
41

jqw

JQ compiled to WebAssembly
TypeScript
2
star
42

skip-loader

A loader that returns an empty string module
JavaScript
2
star
43

lame-svn

Git mirror
C
2
star
44

gulp-recipes

Tiny gulp recipes
1
star