WebRTCでやれよ!と言われそうなところですが、 WebSocket+WebAudioの組み合わせで音声ストリーミングをシンプルに構成する方法を紹介してみます。
サーバーサイドは何でも良いのですが、
とりあえずNode.jsでtest.mp3というサンプルファイルをpcmモジュールでデコードし、
wsでクライアントに垂れ流す作りにしておきます。
| // Copyright (c) 2012 Calvin Rien | |
| // http://the.darktable.com | |
| // | |
| // This software is provided 'as-is', without any express or implied warranty. In | |
| // no event will the authors be held liable for any damages arising from the use | |
| // of this software. | |
| // | |
| // Permission is granted to anyone to use this software for any purpose, | |
| // including commercial applications, and to alter it and redistribute it freely, | |
| // subject to the following restrictions: |
| // stats.js r9 - http://github.com/mrdoob/stats.js | |
| var Stats=function(){var h,a,r=0,s=0,i=Date.now(),u=i,t=i,l=0,n=1E3,o=0,e,j,f,b=[[16,16,48],[0,255,255]],m=0,p=1E3,q=0,d,k,g,c=[[16,48,16],[0,255,0]];h=document.createElement("div");h.style.cursor="pointer";h.style.width="80px";h.style.opacity="0.9";h.style.zIndex="10001";h.addEventListener("mousedown",function(a){a.preventDefault();r=(r+1)%2;0==r?(e.style.display="block",d.style.display="none"):(e.style.display="none",d.style.display="block")},!1);e=document.createElement("div");e.style.textAlign= | |
| "left";e.style.lineHeight="1.2em";e.style.backgroundColor="rgb("+Math.floor(b[0][0]/2)+","+Math.floor(b[0][1]/2)+","+Math.floor(b[0][2]/2)+")";e.style.padding="0 0 3px 3px";h.appendChild(e);j=document.createElement("div");j.style.fontFamily="Helvetica, Arial, sans-serif";j.style.fontSize="9px";j.style.color="rgb("+b[1][0]+","+b[1][1]+","+b[1][2]+")";j.style.fontWeight="bold";j.innerHTML="FPS";e.appendChild(j);f=document.createElement("div");f.style.position="relati |
| /*--- checkForBadJavascripts() | |
| This is a utility function, meant to be used inside a Greasemonkey script that | |
| has the "@run-at document-start" directive set. | |
| It Checks for and deletes or replaces specific <script> tags. | |
| */ | |
| function checkForBadJavascripts (controlArray) { | |
| /*--- Note that this is a self-initializing function. The controlArray | |
| parameter is only active for the FIRST call. After that, it is an | |
| event listener. |
| /* ************************************************************************** | |
| Copyright 2012 Calvin Rien | |
| (http://the.darktable.com) | |
| Derived from a method in BuildManager, part of | |
| VoxelBoy's Unite 2012 Advanced Editor Scripting Talk. | |
| (http://bit.ly/EditorScripting) | |
| Licensed under the Apache License, Version 2.0 (the "License"); | |
| you may not use this file except in compliance with the License. |
| using System; | |
| using System.Collections; | |
| using System.Collections.Generic; | |
| using UnityEditor; | |
| using UnityEngine; | |
| using Object = UnityEngine.Object; | |
| namespace Swing.Editor | |
| { | |
| public class EditorCoroutine |
| using UnityEngine; | |
| public class EnumFlagAttribute : PropertyAttribute | |
| { | |
| public string enumName; | |
| public EnumFlagAttribute() {} | |
| public EnumFlagAttribute(string name) | |
| { |
| /** | |
| * VH and VW units can cause issues on iOS devices: http://caniuse.com/#feat=viewport-units | |
| * | |
| * To overcome this, create media queries that target the width, height, and orientation of iOS devices. | |
| * It isn't optimal, but there is really no other way to solve the problem. In this example, I am fixing | |
| * the height of element `.foo` —which is a full width and height cover image. | |
| * | |
| * iOS Resolution Quick Reference: http://www.iosres.com/ | |
| */ | |
| using UnityEngine; | |
| /* | |
| * Most functions taken from Tween.js - Licensed under the MIT license | |
| * at https://github.com/sole/tween.js | |
| * Quadratic.Bezier by @fonserbc - Licensed under WTFPL license | |
| */ | |
| public delegate float EasingFunction(float k); | |
| public class Easing |
| public static class DebugUtil | |
| { | |
| public static void DumpRenderTexture(RenderTexture rt, string pngOutPath) | |
| { | |
| var oldRT = RenderTexture.active; | |
| var tex = new Texture2D(rt.width, rt.height); | |
| RenderTexture.active = rt; | |
| tex.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0); |