H5采集pcm流转换采样率实时发送到服务端
function startTalk(ws2, button) {
var arrBuffer = new ArrayBuffer(320 * 2);
var sendBuffer = new DataView(arrBuffer);
var sendBufferindex = 0;
if (navigator.getUserMedia) {
navigator.getUserMedia(
{ audio: true },
function (stream) {
button.text("挂 断")
button.attr("status","doing")
var context = new AudioContext();
var audioInput = context.createMediaStreamSource(stream);
var recorder = context.createScriptProcessor(1024, 1, 1);
audioInput.connect(recorder);
recorder.connect(context.destination);
recorder.onaudioprocess = function (e) {
var buffer = e.inputBuffer.getChannelData(0);
var arrayBuffer = context.createBuffer(1, 1024, context.sampleRate);
var nowBuffering = arrayBuffer.getChannelData(0);
for (var i = 0; i < arrayBuffer.length; i++) {
nowBuffering[i] = buffer[i]
}
var offctx = new OfflineAudioContext(1, parseInt(1024*16000/context.sampleRate), 16000);
var source = offctx.createBufferSource();
source.buffer = arrayBuffer;
source.connect(offctx.destination);
source.start();
offctx.startRendering().then(function(renderedBuffer) {
var channetData = renderedBuffer.getChannelData(0)
source.stop();
var index = 0
var length = channetData.length
while (index < length) {
var selectBuffer = channetData[index]
var s = Math.max(-1, Math.min(1, selectBuffer));
var point = s < 0 ? s * 0x8000 : s * 0x7FFF;
if (sendBufferindex < 320 * 2) {
sendBuffer.setInt16(sendBufferindex, point, true);
} else {
var sendData = {
"cmd":"pcm",
"data":{
"buffer": Array.from(new Int16Array(arrBuffer)),
"timestamp": new Date().getTime(),
}
}
if(ws2.readyState == ws2.CLOSING || ws2.readyState == ws2.CLOSED) {
recorder.disconnect()
return
}
ws2.send(JSON.stringify(sendData))
sendBuffer = new DataView(arrBuffer);
sendBufferindex = 0;
sendBuffer.setInt16(sendBufferindex, point, true);
}
index++;
sendBufferindex = sendBufferindex + 2;
}
})
}
},
function() {
ws2.close()
button.attr("status","close")
button.text("通 话")
alert('请插入耳机');
H5采集pcm流转换采样率实时发送到服务端的更多相关文章
- node.js平台下,cropper.js实现图片裁剪预览并转换为base64发送至服务端。
一 .准备工作 1.首先需要先下载cropper,常规使用npm,进入项目路径后执行以下命令: npm install cropper 2. cropper基于jquery,在此不要忘记引入jq,同时 ...
- cropper.js实现图片裁剪预览并转换为base64发送至服务端。
一 .准备工作 1.首先需要先下载cropper,常规使用npm,进入项目路径后执行以下命令: npm install cropper 2. cropper基于jquery,在此不要忘记引入jq,同时 ...
- cookie是如何保存到客户端,又是如何发送到服务端
Cookie相关的Http头 有 两个Http头部和Cookie有关:Set-Cookie和Cookie. Set-Cookie由服务器发送,它包含在响应请求的头部中.它用于在客户端创 ...
- 微信小程序填坑之路其一:wx.request发送与服务端接受
一.序言 应公司要求要求,要用小程序开发一个信息录入系统.没办法只能听话来填坑. 先介绍一下环境:客户端——小程序:服务端——java:数据库——mysql:服务器——centos7 需求:客户端输入 ...
- C#socket客户端自己输入消息发送到服务端通信实现通信
一,服务端代码 using System; using System.Collections.Generic; using System.Linq; using System.Text; using ...
- 记录下httpclient 发送请求 服务端用@RequestBody 自动接收参数 报415
注解是post方式,那么检查以下内容:1. 你是否用了post请求2. 请求是否发送了数据3. 请求内容格式需要是 application/json .jquery 设置 contentType,-- ...
- 基于NIO的同步非阻塞编程完整案例,客户端发送请求,服务端获取数据并返回给客户端数据,客户端获取返回数据
这块还是挺复杂的,挺难理解,但是多练几遍,多看看研究研究其实也就那样,就是一个Selector轮询的过程,这里想要双向通信,客户端和服务端都需要一个Selector,并一直轮询, 直接贴代码: Ser ...
- PHP-Socket服务端客户端发送接收通信实例详解
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://fighter.blog.51cto.com/1318618/1533957 So ...
- rtsp实时流通过rtmp推送到服务端
很多朋友都会问到rtsp如何通过rtmp协议推送到服务端,正好前段时间开发了这个功能写在这里,和大家分享下. 首先我想说的是:ffmpeg可以实现这个功能.ffmpeg支持rtsp协议,也支持rtmp ...
随机推荐
- spring boot 入门(一)
转自构建微服务:Spring boot 入门篇 什么是spring boot Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程. ...
- java面试总结(资料来源网络)
core java: 一.集合 1.hashMap 结构如图: HashMap在Map.Entry静态内部类实现中存储key-value对. HashMap使用哈希算法.在put和get方法中.它使用 ...
- 初探LaTeX
第一次使用LaTeX 步骤 1 安装LaTeX 通过官网http://www.tug.org/mactex/mactex-download.html下载Mac版LaTeX. 安装成功后会出现 步骤 ...
- NPOI 修改已存在的excel文件,设置第一行行高
FileStream fileStream = new FileStream(@FileName, FileMode.Open, FileAccess.Read); FileStream fileSt ...
- Vue note
1.npm run build 时,font:xx/xx "xxxx" 这种样式打包后会无效,只能写成font-size:xxx; line-height:xxx; font-fa ...
- U3D 设置帧率与垂直同步
1,设置帧率: Application.targetFrameRate = 60: //-1为无限制 2,垂直同步 project settings -> quality,任何level的垂直同 ...
- ActiveMq Windows 配置优化
最近ActiveMQ 5.15.3 会报 OutofMemory的错误 在 wrapper.conf中 #wrapper.java.additional.8=-Dorg.apache.activemq ...
- Redis 编译安装
系统学习一下,记录一下笔记,之前都是断断续续尝试过一些简单的安装使用 下载,解压 编译安装 copy配置文件 启动连接 ./bin/redis-server ./redis.conf 登陆./bin/ ...
- flex布局-css
1.html <div id="parent"> <div id="child1"></div> <div id=& ...
- Linux Simple Systemd Service Guide
Simple Systemd Service Guide 主题 Systemd介绍 Systemd基本操作 怎样编写_service_.service文件 怎样部署service Systemd介绍 ...