0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Iotラジオ その5

Last updated at Posted at 2016-08-22

概要

配信プログラムは、jsfiddleに置いた。
webrtcが、jsdoで動かないため。
オーディオカードのマイク入力をwebsocketに投げる。

写真

サンプルコード

var ws = new WebSocket("ws://ohijs0.paas.jp-e1.cloudn-service.com/pub");
ws.binaryType = "arraybuffer";
ws.onopen = function(e) {
};
ws.onerror = function(e) {
    alert("err");
    alert(e.msg); 
};
var ac = new AudioContext();
var sampleRate = ac.sampleRate;
var node = ac.createScriptProcessor(4096, 2, 2);
navigator.getMedia = (navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia);
function onStream(stream) {
    var source = ac.createMediaStreamSource(stream);
    node.onaudioprocess = function(e) {
        ws.send(new Float32Array(e.inputBuffer.getChannelData(0)));
    }
    source.connect(node);
    node.connect(ac.destination);
}
function onStreamFailed(err) {
    alert('エラー: ' + err);
}
if (navigator.getMedia) 
{
    var prop = {
        video: false,
        audio: true,
        toString: function() {
            return 'audio';
        }
    };
    navigator.getMedia(prop, onStream, onStreamFailed);
} 
else 
{
    alert('エラー: getUserMediaがサポートされていません');
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?