我正在使用WebGL渲染二进制编码的网格文件.二进制文件以big-endian格式写出(我可以通过在十六进制编辑器中打开文件或使用fiddler查看网络流量来验证这一点).当我尝试使用Float32Array或Int32Array读取二进制响应时,二进制文件被解释为little-endian并且我的值是错误的:
// Interpret first 32bits in buffer as an int
var wrongValue = new Int32Array(binaryArrayBuffer)[0];
Run Code Online (Sandbox Code Playgroud)
我在http://www.khronos.org/registry/typedarray/specs/latest/找不到任何类型数组默认字节序的引用,所以我想知道这笔交易是什么?在使用类型化数组进行读取时,我是否应该假设所有二进制数据都应该是小端?
为了解决这个问题,我可以使用DataView对象(在上一个链接中讨论)并调用:
// Interpret first 32bits in buffer as an int
var correctValue = new DataView(binaryArrayBuffer).getInt32(0);
Run Code Online (Sandbox Code Playgroud)
默认情况下,"getInt32"等DataView函数会读取big-endian值.
(注意:我已经使用Google Chrome 15和Firefox 8进行了测试,它们的行为方式相同)
我正在尝试设置服务器以使用 接收来自客户端浏览器的音频SocketIO,然后通过 Google Speech-to-Text 对其进行处理,最后将文本回复给客户端。
最初和理想情况下,我想设置得有点像此页面上的工具:https : //cloud.google.com/speech-to-text/
我尝试使用getUserMedia和流式传输它SocketIO-Stream,但我不知道如何“管道” MediaStream。
相反,现在我决定MediaRecorder在客户端使用,然后将数据作为 blob 一起发送(见本示例)。
然后我申请toString('base64')blob 并在 blob 上调用 google-cloud/speech client.recognize()。
客户端(我正在使用 VueJS):
new Vue({
el: '#app',
data: function () {
return ({
msgs: [],
socket: null,
recorder: null,
: []
})
},
mounted: function () {
this.socket = io.connect('localhost:3000/user');
console.log('Connected!')
this.socket.on('text', function (text) {
this.msgs.push(text)
})
},
methods: {
startRecording: function () {
if (this.recorder && …Run Code Online (Sandbox Code Playgroud) audio-streaming node.js socket.io getusermedia google-speech-api
有没有办法在使用 MediaRecorder 时在 Chrome 中记录 ogg 格式?我相信,Chrome 默认支持 WebM。以下是我所做的
navigator.mediaDevices.getUserMedia({ audio: true })
.then(stream => {
rec = new MediaRecorder(stream);
rec.ondataavailable = e => {
audioChunks.push(e.data);
if (rec.state == "inactive")
{
let blob = new Blob(audioChunks, { 'type': 'audio/ogg; codecs=opus' });
}
};
})
.catch(e => console.log(e));
Run Code Online (Sandbox Code Playgroud) javascript ×2
arraybuffer ×1
endianness ×1
getusermedia ×1
node.js ×1
socket.io ×1
typed-arrays ×1
webgl ×1