mirror of
https://github.com/musix-org/musix-oss
synced 2025-06-17 07:36:01 +00:00
Modules
This commit is contained in:
17
node_modules/node-opus/examples/mp3-to-ogg.js
generated
vendored
Normal file
17
node_modules/node-opus/examples/mp3-to-ogg.js
generated
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
|
||||
"use strict";
|
||||
|
||||
var fs = require( 'fs' );
|
||||
var lame = require( 'lame' );
|
||||
var opus = require( '../' );
|
||||
var ogg = require( 'ogg' );
|
||||
|
||||
var opusFile = fs.createWriteStream( 'test.opus' );
|
||||
|
||||
var mp3Decoder = new lame.Decoder();
|
||||
var opusEncoder = new opus.Encoder( 48000, 2 );
|
||||
var oggEncoder = new ogg.Encoder();
|
||||
|
||||
process.stdin.pipe( mp3Decoder ).pipe( opusEncoder ).pipe( oggEncoder.stream() );
|
||||
oggEncoder.pipe( process.stdout );
|
||||
|
56
node_modules/node-opus/examples/stream-to-alsa.js
generated
vendored
Normal file
56
node_modules/node-opus/examples/stream-to-alsa.js
generated
vendored
Normal file
@ -0,0 +1,56 @@
|
||||
'use strict';
|
||||
// replace username and password with speech to text credentials
|
||||
// audio.wav can be found here: https://github.com/watson-developer-cloud/nodejs-wrapper/blob/master/test/resources/audio.wav?raw=true
|
||||
|
||||
var fs = require('fs');
|
||||
var opus = require('node-opus');
|
||||
var ogg = require('ogg');
|
||||
var cp = require('child_process');
|
||||
|
||||
var oggDecoder = new ogg.Decoder();
|
||||
|
||||
oggDecoder.on('stream', function (stream) {
|
||||
|
||||
var opusDecoder = new opus.Decoder();
|
||||
|
||||
// the "format" event contains the raw PCM format
|
||||
opusDecoder.on('format', function (format) {
|
||||
|
||||
// format example:
|
||||
//{
|
||||
// channels: 1,
|
||||
// sampleRate: 24000,
|
||||
// bitDepth: 16,
|
||||
// float: false,
|
||||
// signed: true,
|
||||
// gain: 0,
|
||||
// preSkip: 156,
|
||||
// version: 1
|
||||
//}
|
||||
|
||||
// convert the signed & bitDepth to an alsa compatible format (`aplay --help format` for full list)
|
||||
var alsaFormat;
|
||||
if (format.signed && format.bitDepth == 16) {
|
||||
alsaFormat = 'S16_LE'; // assume Little Endian
|
||||
} else {
|
||||
throw new Error('unexpected format: ' + JSON.stringify(format));
|
||||
}
|
||||
|
||||
// set up aplay to accept data from stdin
|
||||
var aplay = cp.spawn('aplay',['--format=' + alsaFormat, '--rate=' + format.sampleRate, '--channels='+format.channels, '--']);
|
||||
|
||||
// send the raw PCM data to aplay
|
||||
opusDecoder.pipe(aplay.stdin);
|
||||
|
||||
// or pipe to node-speaker, a file, etc
|
||||
});
|
||||
|
||||
// an "error" event will get emitted if the stream is not a Vorbis stream
|
||||
// (i.e. it could be a Theora video stream instead)
|
||||
opusDecoder.on('error', console.error);
|
||||
|
||||
stream.pipe(opusDecoder);
|
||||
});
|
||||
|
||||
|
||||
fs.createReadStream('input.opus').pipe(oggDecoder);
|
Reference in New Issue
Block a user