Guest User

Untitled

a guest
Apr 27th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.16 KB | None | 0 0
  1. (function(window){
  2.  
  3. var WORKER_PATH = '../js/recorderjs/recorderWorker.js';
  4.  
  5. var Recorder = function(source, cfg){
  6. var config = cfg || {};
  7. var bufferLen = config.bufferLen || 4096;
  8. this.context = source.context;
  9. if(!this.context.createScriptProcessor){
  10. this.node = this.context.createJavaScriptNode(bufferLen, 2, 2);
  11. } else {
  12. this.node = this.context.createScriptProcessor(bufferLen, 2, 2);
  13. }
  14.  
  15. var worker = new Worker(config.workerPath || WORKER_PATH);
  16. worker.postMessage({
  17. command: 'init',
  18. config: {
  19. sampleRate: this.context.sampleRate
  20. }
  21. });
  22. var recording = false,
  23. currCallback;
  24.  
  25. this.node.onaudioprocess = function(e){
  26. if (!recording) return;
  27. worker.postMessage({
  28. command: 'record',
  29. buffer: [
  30. e.inputBuffer.getChannelData(0),
  31. e.inputBuffer.getChannelData(1)
  32. ]
  33. });
  34. }
  35.  
  36. this.configure = function(cfg){
  37. for (var prop in cfg){
  38. if (cfg.hasOwnProperty(prop)){
  39. config[prop] = cfg[prop];
  40. }
  41. }
  42. }
  43.  
  44. this.record = function(){
  45. recording = true;
  46. }
  47.  
  48. this.stop = function(){
  49. recording = false;
  50. }
  51.  
  52. this.clear = function(){
  53. worker.postMessage({ command: 'clear' });
  54. }
  55.  
  56. this.getBuffers = function(cb) {
  57. currCallback = cb || config.callback;
  58. worker.postMessage({ command: 'getBuffers' })
  59. }
  60.  
  61. this.exportWAV = function(cb, type){
  62. currCallback = cb || config.callback;
  63. type = type || config.type || 'audio/wav';
  64. if (!currCallback) throw new Error('Callback not set');
  65. worker.postMessage({
  66. command: 'exportWAV',
  67. type: type
  68. });
  69. }
  70.  
  71. this.exportMonoWAV = function(cb, type){
  72. currCallback = cb || config.callback;
  73. type = type || config.type || 'audio/wav';
  74. if (!currCallback) throw new Error('Callback not set');
  75. worker.postMessage({
  76. command: 'exportMonoWAV',
  77. type: type
  78. });
  79. }
  80.  
  81. worker.onmessage = function(e){
  82. var blob = e.data;
  83. currCallback(blob);
  84. }
  85.  
  86. source.connect(this.node);
  87. this.node.connect(this.context.destination); // if the script node is not connected to an output the "onaudioprocess" event is not triggered in chrome.
  88. };
  89.  
  90. Recorder.setupDownload = function(blob, filename){
  91. var url = (window.URL || window.webkitURL).createObjectURL(blob);
  92. var link = document.getElementById("save");
  93. var audioinput = document.getElementById("audioinput");
  94. link.href = url;
  95. link.download = filename || 'output.wav';
  96. }
  97.  
  98. window.Recorder = Recorder;
  99.  
  100. })(window);
  101.  
  102. (function(window){
  103.  
  104. var WORKER_PATH = '../js/recorderjs/recorderWorker.js';
  105.  
  106. var Recorder = function(source, cfg){
  107. var config = cfg || {};
  108. var bufferLen = config.bufferLen || 4096;
  109. this.context = source.context;
  110. if(!this.context.createScriptProcessor){
  111. this.node = this.context.createJavaScriptNode(bufferLen, 2, 2);
  112. } else {
  113. this.node = this.context.createScriptProcessor(bufferLen, 2, 2);
  114. }
  115.  
  116. var worker = new Worker(config.workerPath || WORKER_PATH);
  117. worker.postMessage({
  118. command: 'init',
  119. config: {
  120. sampleRate: this.context.sampleRate
  121. }
  122. });
  123. var recording = false,
  124. currCallback;
  125.  
  126. this.node.onaudioprocess = function(e){
  127. if (!recording) return;
  128. worker.postMessage({
  129. command: 'record',
  130. buffer: [
  131. e.inputBuffer.getChannelData(0),
  132. e.inputBuffer.getChannelData(1)
  133. ]
  134. });
  135. }
  136.  
  137. this.configure = function(cfg){
  138. for (var prop in cfg){
  139. if (cfg.hasOwnProperty(prop)){
  140. config[prop] = cfg[prop];
  141. }
  142. }
  143. }
  144.  
  145. this.record = function(){
  146. recording = true;
  147. }
  148.  
  149. this.stop = function(){
  150. recording = false;
  151. }
  152.  
  153. this.clear = function(){
  154. worker.postMessage({ command: 'clear' });
  155. }
  156.  
  157. this.getBuffers = function(cb) {
  158. currCallback = cb || config.callback;
  159. worker.postMessage({ command: 'getBuffers' })
  160. }
  161.  
  162. this.exportWAV = function(cb, type){
  163. currCallback = cb || config.callback;
  164. type = type || config.type || 'audio/wav';
  165. if (!currCallback) throw new Error('Callback not set');
  166. worker.postMessage({
  167. command: 'exportWAV',
  168. type: type
  169. });
  170. }
  171.  
  172. this.exportMonoWAV = function(cb, type){
  173. currCallback = cb || config.callback;
  174. type = type || config.type || 'audio/wav';
  175. if (!currCallback) throw new Error('Callback not set');
  176. worker.postMessage({
  177. command: 'exportMonoWAV',
  178. type: type
  179. });
  180. }
  181.  
  182. worker.onmessage = function(e){
  183. var blob = e.data;
  184. currCallback(blob);
  185. }
  186.  
  187. source.connect(this.node);
  188. this.node.connect(this.context.destination); // if the script node is not connected to an output the "onaudioprocess" event is not triggered in chrome.
  189. };
  190. Recorder.setupDownload = function(blob, filename) {
  191.  
  192. //Download button
  193. //var url = (window.URL || window.webkitURL).createObjectURL(blob);
  194. //var link = document.getElementById("save");
  195. //link.href = url;
  196. //link.download = filename || 'output.wav';
  197. //
  198.  
  199. var fd = new FormData();
  200. fd.append('fname', filename);
  201. fd.append('data', blob);
  202. $.ajax({
  203. type: 'POST',
  204. url: 'upload.php',
  205. data: fd,
  206. processData: false,
  207. contentType: false,
  208. }).done(function(data) {
  209. console.log(data);
  210. });
  211. }
  212.  
  213. window.Recorder = Recorder;
  214.  
  215. })(window);
  216.  
  217. $p_audio = $_POST['data'];
  218. $p_audio_name = $_FILES['data']['name'];
  219. $p_audio_type = $_FILES['data']['type'];
  220. $p_audio_temp = $_FILES['data']['tmp_name'];
  221.  
  222. $id1 = mt_rand(0, 9999999);
  223. $id2 = mt_rand(0, 9999999);
  224. $id3 = mt_rand(0, 9999999);
  225. $id4 = mt_rand(0, 9999999);
  226. $id5 = mt_rand(0, 9999999);
  227. $id6 = mt_rand(0, 9999999);
  228. $id7 = mt_rand(0, 9999999);
  229. $id8 = mt_rand(0, 9999999);
  230. $id9 = mt_rand(0, 9999999);
  231. $id10 = mt_rand(0, 9999999);
  232. $id11 = mt_rand(0, 9999999);
  233.  
  234. //Conditionals
  235. if ($p_audio_type === "audio/wav" || $p_audio_type === "audio/wave" || $p_audio_type === "audio/x-wave" || $p_audio_type === "audio/vnd.wave"){$p_audio_type = ".wav";
  236. move_uploaded_file($p_audio_temp, "../yourmedia/".$id1.$id2.$id3.$id4.$id5.$id6.$id7.$id8.$id9.$id10.$id11.$p_audio_type);
  237. }
  238. if ($p_audio_type === "audio/wav" || $p_audio_type === "audio/wave" || $p_audio_type === "audio/x-wave" || $p_audio_type === "audio/vnd.wave"){$p_audio_type = ".wav";
  239. move_uploaded_file($p_audio_temp, "../yourmedia/".$id1.$id2.$id3.$id4.$id5.$id6.$id7.$id8.$id9.$id10.$id11.$p_audio_type);
  240. }
  241.  
  242. Recorder.setupDownload = function(blob, filename) {
  243. var fd = new FormData();
  244. fd.append('fname', filename);
  245. fd.append('data', blob);
  246. $.ajax({
  247. type: 'POST',
  248. url: '/upload.php',
  249. data: fd,
  250. processData: false,
  251. contentType: false
  252. }).done(function(data) {
  253. console.log(data);
  254. });
  255. }
Add Comment
Please, Sign In to add comment