GithubHelp home page GithubHelp logo

ang-yc / wx-voice Goto Github PK

View Code? Open in Web Editor NEW
140.0 4.0 36.0 646 KB

Convert audio files between Tencent apps (Weixin / Wechat, QQ) and Silk codec with other general formats such as MP3 and M4A

License: MIT License

JavaScript 1.25% Makefile 0.23% C 80.16% Assembly 11.69% C++ 4.70% Objective-C 1.97%
wechat weixin mini program silk slk convert converter decode decoder

wx-voice's Introduction

wx-voice npm

Convert audio files between Tencent apps (Weixin / Wechat, QQ) and Silk codec with other general formats such as MP3 and M4A
中文版

Install

$ npm install wx-voice --save
$ npm install wx-voice -g
$ wx-voice compile

Prerequisites

CLI Usage

wx-voice <command> <options>

Example:
$ wx-voice decode -i input.silk -o output.mp3 -f mp3
$ wx-voice encode -i input.mp3 -o output.silk -f silk

CLI

Command:
  decode    decode to general audio format
  encode    encode from general audio format
  compile   compile wx-voice library
  clean     remove compiled library

Options:
  -i <input>    input file path
  -o <output>   output file path
  -f <format>   format of the output file
  --bitrate     bitrate of the output file
  --frequency   frequency of the output file
  --channels    channels of the output file

API Usage

// Initialize
const WxVoice = require('wx-voice');
var voice = new WxVoice();

// Error handler
voice.on("error", (err) => console.log(err));

// Decode silk to MP3
voice.decode(
    "input.silk", "output.mp3", { format: "mp3" },
    (file) => console.log(file));

// Output: "/path/to/output.mp3"

API

new WxVoice([tempFolder, [ffmpegPath]])

Initialize wxVoice object

Parameter Description
tempFolder Folder of temporary files, default to system temporary
ffmpegPath Custom path to ffmpeg executables, default using $PATH

decode(input, output, [options, [callback]])

Decode the audio to general formats

encode(input, output, [options, [callback]])

Encode the audio to silk/webm format

Parameter Description
input Input audio path
output Output audio path
options Output options (JS Object), see Options
callback Callback with output as parameter when decode success, undefined otherwise
voice.encode(
    "input.mp3", "output.silk", { format: "silk" },
    (file) => console.log(file));

// Output: "/path/to/output.silk"

duration(filePath, [callback])

Get the duration of the audio file
(Decode to general audio format before calling this method)

Parameter Description
filePath File path to the audio
callback Callback with duration of the audio in second as parameter when decode success, 0 otherwise
voice.encode("output.mp3", (dur) => console.log(dur));
// Output: "10.290"

Options

Javascript Object to set options for the output file

Parameter Description
format Format to be encoded/decoded (silk, webm, mp3, m4a...), default parse from output
bitrate Bitrate of the output, bps unit
frequency Frequency of the output, Hz unit
channels Channels of the output, default to 1

File types

Decode: Tested on mp3, m4a, wav, pcm
Encode: Tested on silk, silk_amr, webm

Todo

  • Use options as parameter instead of multiple arguments
  • Timeout to stop the convert process if it takes too long
  • Batch conversion using command line
  • Support Windows

Installing build tools

OS Command
Ubuntu sudo apt-get install build-essential
CentOS sudo yum groupinstall 'Development Tools'
Mac Download XCode

Installing ffmpeg

Ubuntu

$ sudo add-apt-repository ppa:mc3man/trusty-media  
$ sudo apt-get update  
$ sudo apt-get install ffmpeg

CentOS

$ sudo yum install epel-release
$ sudo yum update
$ sudo rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro

For CentOS 7:

$ sudo rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm

For CentOS 6:

$ sudo rpm -Uvh http://li.nux.ro/download/nux/dextop/el6/x86_64/nux-dextop-release-0-2.el6.nux.noarch.rpm

Install FFMPEG:

$ sudo yum install ffmpeg

Mac

$ brew install ffmpeg

License

MIT © Ang YC

wx-voice's People

Contributors

ang-yc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

wx-voice's Issues

转换silk到mp3格式报错:ERROR decode not successful, file not supported

choogoo@Tommys-MacBook-Pro WechatyS3Plugin % wx-voice compile
[wx-voice] ⠋ Running command: compile-1
[wx-voice] compile-1 success
[wx-voice] ⠇ Running command: compile-2
[wx-voice] compile-2 success
choogoo@Tommys-MacBook-Pro WechatyS3Plugin % wx-voice decode -i 1004016.silk -o output.mp3 -f mp3
[wx-voice] ⠙ Running command: decode
[wx-voice] ERROR decode not successful, file not supported
choogoo@Tommys-MacBook-Pro WechatyS3Plugin % wx-voice decode -i ./1004016.silk -o output.mp3 -f mp3
[wx-voice] ⠹ Running command: decode
[wx-voice] ERROR decode not successful, file not supported
choogoo@Tommys-MacBook-Pro WechatyS3Plugin % wx-voice encode -i 11582.mp3 -o output.silk -f silk
[wx-voice] ⠴ Running command: encode
[wx-voice] encode success
choogoo@Tommys-MacBook-Pro WechatyS3Plugin % wx-voice decode -i output.silk -o output.mp3 -f mp3
[wx-voice] ⠹ Running command: decode
[wx-voice] ERROR decode not successful, file not supported
choogoo@Tommys-MacBook-Pro WechatyS3Plugin %

nodejs 中的使用, 文件路径是怎么放的呢?

voice.decode(
"input.silk", "output.mp3", { format: "mp3" },
(file) => console.log(file));

您好,请问上面代码中的 文件路径 是怎么放的,我的nodejs 是 express的,文件路径是绝对路径吗?
我在mac本地执行了没效果

提一个文档错误

哈哈,先笑一下。
看下voice.duration(...)的文档的例子,写成了voice.encode。
再次感谢,哈哈。。。

运行报错,提示 Silk SDK not found

已安装 ffmpeg 和 Development Tools

CentOS Linux release 7.5.1804 (Core)

NodeJs v8.1.4

代码

const WxVoice = require('wx-voice');
var voice = new WxVoice();

报错

throw new Error("Silk SDK not found, make sure you compiled using command: wx-voice compile");

能不能加入直接导出PCM格式的选项呢?

很多场景都是需要直接处理PCM数据的。例如百度的语音服务,讯飞的语音服务。看了下源码,目前也是先转成了pcm再转成其他的格式的。能不能直接添加导出pcm的选项呢?

转成silk后,在转会mp3报错

我在mac上是可以的,一切正常。录制的mp3转成silk通过微信发送,可以成功,并且可以播放。
迁移到Ubuntu 16.04后,录制的mp3能转成silk, 也能发送成功,但是点播放,没有任何声音。

我在Ubuntu上尝试了以下操作,转化之后的silk,在转回mp3的时候会报错,所以我怀疑mp3在转silk的时候有点问题。能给点什么建议吗?

非常感谢。

wx-voice encode 62b628c00d72fe9168a00d78.mp3 ./62b628c00d72fe9168a00d78.silk silk
[wx-voice]  ⠧ Running command: encode
[wx-voice]  encode success
wx-voice decode 62b628c00d72fe9168a00d78.silk ./aaaa.mp3 mp3
[wx-voice]  ⠴ Running command: decode
[wx-voice]  ERROR  decode not successful, file not supported

环境信息:
ubuntu 16.04
ffmpeg version 3.3.4-116.04.york0 Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1
16.04.4) 20160609
configuration: --prefix=/usr --extra-version='1~16.04.york0' --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
libavutil 55. 58.100 / 55. 58.100
libavcodec 57. 89.100 / 57. 89.100
libavformat 57. 71.100 / 57. 71.100
libavdevice 57. 6.100 / 57. 6.100
libavfilter 6. 82.100 / 6. 82.100
libavresample 3. 5. 0 / 3. 5. 0
libswscale 4. 6.100 / 4. 6.100
libswresample 2. 7.100 / 2. 7.100
libpostproc 54. 5.100 / 54. 5.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.