├── .babelrc ├── .editorconfig ├── .eslintrc ├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── build ├── build.js └── webpack.config.js ├── dist └── webvoice.js ├── docs ├── api.md ├── assets │ ├── design.png │ ├── horse.mp3 │ ├── horse.ogg │ └── horse.wav ├── audio.swf ├── class.doc ├── dist │ └── webvoice.js ├── expressInstall.swf ├── index.html └── swfobject.js ├── https_server ├── certificate.pem ├── certrequest.csr ├── index.js └── privatekey.pem ├── index.js ├── package.json ├── src ├── audio.js ├── config.js ├── core │ ├── as3context.js │ ├── audio.js │ ├── context.js │ ├── incontext.js │ ├── media.js │ ├── outcontext.js │ └── player.js ├── io │ ├── blob.js │ ├── decoder.js │ └── encoder.js ├── net │ ├── ws.js │ └── xhr.js └── utils │ ├── browser.js │ ├── exception.js │ ├── log.js │ └── pollfill.js └── yarn.lock /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "env" 4 | ] 5 | } -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dehai168/webvoice/7f3dc96ad381865e98b8d8272b0af4dd13af8369/.editorconfig -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "es6": true 4 | }, 5 | "parserOptions": { 6 | "sourceType": "module" 7 | } 8 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | npm-debug.log 3 | dist/audio.swf 4 | dist/expressInstall.swf 5 | dist/swfobject.js 6 | package-lock.json 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dehai168/webvoice/7f3dc96ad381865e98b8d8272b0af4dd13af8369/.travis.yml -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 wangdehai. All Rights Reserved. 3 | * 4 | * @author level 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # webvoice 2 | >一个网页语音对讲库。 3 | 4 | ### 使用 5 | 6 | ```js 7 | npm install webvoice --save 8 | ``` 9 | ### 设计 10 | 11 | ![](https://github.com/dehai168/webvoice/blob/master/docs/assets/design.png) 12 | 13 | ### 采集 14 | 1. 通过`MediaDevices.getUserMedia()`进行语音采集 15 | 2. 需要在`https`的环境下调用 16 | 3. 把麦克风数据塞给 `MediaStreamAudioSourceNode` 17 | ### 编码 18 | 1. 建立`ScriptProcessNode`处理节点 19 | 2. 把建立的 `MediaStreamAudioSourceNode` 连接到 `ScriptProcessNode` 然后连接到 `AudioContext.destination` 20 | 3. 在`ScriptProcessNode`的 `onaudioprocess` 事件中处理 `Buffer` 21 | 4. 把 `Buffer` 进行压缩和 `wav` 编码 22 | ### 传输 23 | 1. 通过`websocket`加密方式进行传输 24 | ### 处理 25 | 1. 任意后台进行数据处理 `node/java/c#/c++` 26 | 2. 然后转发到目的地 27 | 3. 把结果通过`websocket`发送出来 28 | ### 接收 29 | 1. 通过`websocket`进行接收 30 | ### 解码 31 | 1. 通过 `AudioContext` 的 `decodeAudioData` 方法对 `wav` 格式音频文件解码 32 | ### 播放 33 | 1. 构建`AudioBufferSourceNode`节点 34 | 2. 连接到 `AudioContext.destination` 并进行播放 35 | 36 | ### Document 37 | 38 | [API](https://github.com/dehai168/webvoice/blob/master/docs/api.md) 39 | 40 | ### 音频格式浏览器支持情况 41 | 42 | |内容\浏览器|Chrome|IE|FireFox|Safari|Opera| 43 | |---|---|---|---|---|---| 44 | |`