Permalink
Browse files

recording using jRecorder (flash based) is now added

  • Loading branch information...
1 parent 5b6793c commit 7282e2ae24ea4f0e6d39dca4578edfb0ecb3b563 @zoharbabin committed Oct 13, 2012
Showing with 513 additions and 8 deletions.
  1. +25 −0 acceptfile.php
  2. +2 −5 config.php
  3. +119 −3 index.php
  4. +244 −0 jRecorder.js
  5. BIN jRecorder.swf
  6. BIN jRecorder.swf.bu
  7. +36 −0 log_file.log
  8. +87 −0 mictest.php
  9. BIN watson-audio.wav
  10. BIN watson.wav
View
25 acceptfile.php
@@ -0,0 +1,25 @@
+<?php
+
+ if(!isset($_REQUEST['filename']))
+ {
+ exit('No file');
+ }
+
+ $upload_path = dirname(__FILE__). '/';
+
+ $filename = $_REQUEST['filename'];
+
+ $fp = fopen($upload_path."/".$filename.".wav", "wb");
+
+ fwrite($fp, file_get_contents('php://input'));
+
+ fclose($fp);
+
+ $commandString = 'ffmpeg -i watson.wav -y -ar 8000 -ab 16 -ac 1 watson-audio.wav >> log_file.log 2>&1 &';
+ $command = exec($commandString);
+
+ exit('done');
+
+
+
+?>
View
7 config.php
@@ -5,12 +5,9 @@
-->
<?php
- $api_key = "";
- $secret_key = "";
+ $api_key = "a2cd167e4127315ef580feb9526826b0";
+ $secret_key = "ddbbff991a11a803";
$FQDN = "https://api.att.com";
$scope = "SPEECH";
$oauth_file = ".../tmp/speechoauthtoken.php";
-
-
?>
-
View
122 index.php
@@ -176,6 +176,9 @@ function check_token( $FQDN,$api_key,$secret_key,$scope, $fullToken,$oauth_file)
<title>AT&amp;T Sample Speech Application - Speech to Text (Generic) Application</title>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
<link rel="stylesheet" type="text/css" href="style/common.css"/>
+ <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
+ <script src="jRecorder.js"> </script>
+
</head>
<body>
<div id="container">
@@ -227,15 +230,128 @@ function check_token( $FQDN,$api_key,$secret_key,$scope, $fullToken,$oauth_file)
<tbody>
<tr>
<td width="20%" valign="top" class="label">Audio File:</td>
- <td class="cell"><input name="f1" type="file"></td>
+ <!--td class="cell"><input name="f1" type="file"></td-->
+ <td class="cell">
+ <div id="locationforrecorder" style="border:1px solid grey">
+ </div>
+ <script>
+
+ $.jRecorder(
+
+ {
+ host : 'http://54.242.49.145/watsongangham/acceptfile.php?filename=watson' ,
+// host : 'acceptfile.php?filename=watsonaudio' ,
+ callback_started_recording: function(){callback_started(); },
+ callback_stopped_recording: function(){callback_stopped(); },
+ callback_activityLevel: function(level){callback_activityLevel(level); },
+ callback_activityTime: function(time){callback_activityTime(time); },
+
+ callback_finished_sending: function(time){ callback_finished_sending() },
+
+
+ swf_path : 'jRecorder.swf',
+
+ }
+
+ , $('#locationforrecorder')
+
+
+ );
+
+
+
+ </script>
+<div style="background-color: #eeeeee;border:1px solid #cccccc">
+
+ Time: <span id="time">00:00</span>
+
+</div>
+
+
+<div>
+ Level: <span id="level"></span>
+</div>
+
+<div id="levelbase" style="width:200px;height:20px;background-color:#ffff00">
+
+ <div id="levelbar" style="height:19px; width:2px;background-color:red"></div>
+
+</div>
+
+<div>
+ Status: <span id="status"></status>
+</div>
+<input type="button" id="record" value="Record" style="color:red">
+<input type="button" id="stop" value="Stop">
+<script type="text/javascript">
+ $('#record').click(function(){
+ $.jRecorder.record(30);
+ })
+
+ $('#stop').click(function(){
+ $.jRecorder.stop();
+ $.jRecorder.sendData();
+ })
+
+ function callback_finished()
+ {
+ $('#status').html('Recording is finished');
+ }
+
+ function callback_started()
+ {
+ $('#status').html('Recording is started');
+ }
+
+ function callback_error(code)
+ {
+ $('#status').html('Error, code:' + code);
+ }
+
+ function callback_stopped()
+ {
+ $('#status').html('Stop request is accepted');
+ }
+
+ function callback_finished_recording()
+ {
+ $('#status').html('Recording event is finished');
+ }
+
+ function callback_finished_sending()
+ {
+ $('#status').html('File has been sent to server mentioned as host parameter');
+ }
+
+ function callback_activityLevel(level)
+ {
+ $('#level').html(level);
+ if(level == -1)
+ {
+ $('#levelbar').css("width", "2px");
+ }
+ else
+ {
+ $('#levelbar').css("width", (level * 2)+ "px");
+ }
+ }
+
+ function callback_activityTime(time)
+ {
+ //$('.flrecorder').css("width", "1px");
+ //$('.flrecorder').css("height", "1px");
+ $('#time').html(time);
+ }
+ </script>
+ </td>
</tr>
<tr>
<td />
<td>
<div id="extraleft">
<div class="warning">
<strong>Note:</strong><br />
- If no file is chosen, a <a href="./bostonSeltics.wav">default.wav</a> file will be loaded on submit.<br />
+ After recording your gangham, wait untill the playback finishes and then click submit and wait till watson magically print the song!<br />
<strong>Speech file format constraints:</strong> <br />
. 16 bit PCM WAV, single channel, 8 kHz sampling<br />
. AMR (narrowband), 12.2 kbit/s, 8 kHz sampling<br />
@@ -283,7 +399,7 @@ function check_token( $FQDN,$api_key,$secret_key,$scope, $fullToken,$oauth_file)
if($filename == null) {
- $filename = dirname(__FILE__).'/bostonSeltics.wav';
+ $filename = dirname(__FILE__).'/watson-audio.wav';
$file_binary = fread(fopen($filename, 'rb'), filesize($filename));
} else{
View
244 jRecorder.js
@@ -0,0 +1,244 @@
+/*
+ * jRecorder Plugin for jQuery JavaScript Library (Alpha)
+ * http://www.sajithmr.me/jrecorder
+ *
+ * Copyright (c) 2011 - 2013 Sajithmr.ME
+ * Dual licensed under the MIT and GPL licenses.
+ * - http://www.opensource.org/licenses/mit-license.php
+ * - http://www.gnu.org/copyleft/gpl.html
+ *
+ * Author: Sajith Amma
+ * Version: 1.1
+ * Date: 14 December 2011
+ */
+
+/* Code is not verified using http://www.jshint.com/ */
+
+
+(function ($){
+
+
+ var methods = {
+ play : function( options ) {
+
+ alert(options);
+
+ },
+ pause : function( ) { }
+
+ };
+
+
+ var jRecorderSettings = {} ;
+
+ $.jRecorder = function( options, element ) {
+ // allow instantiation without initializing for simple inheritance
+
+
+ if(typeof(options) == "string")
+ {
+ if ( methods[options] )
+ {
+ return methods[ options ].apply( this, Array.prototype.slice.call( arguments, 1 ));
+
+ }
+ return false;
+ }
+
+ //if the element to be appended is not defind, append to body
+ if(element == undefined)
+ {
+ element = $("body");
+ }
+
+ //default settings
+ var settings = {
+
+ 'rec_width': '300',
+ 'rec_height': '200',
+ 'rec_top': '0px',
+ 'rec_left': '0px',
+ 'recorderlayout_id' : 'flashrecarea',
+ 'recorder_id' : 'audiorecorder',
+ 'recorder_name': 'audiorecorder',
+ 'wmode' : 'transparent',
+ 'bgcolor': '#ff0000',
+ 'swf_path': 'jRecorder.swf',
+ 'host': 'acceptfile.php?filename=hello.wav',
+ 'callback_started_recording' : function(){},
+ 'callback_finished_recording' : function(){},
+ 'callback_stopped_recording': function(){},
+ 'callback_error_recording' : function(){},
+ 'callback_activityTime': function(time){},
+ 'callback_activityLevel' : function(level){}
+
+
+
+
+
+ };
+
+
+ //if option array is passed, merget the values
+ if ( options ) {
+ $.extend( settings, options );
+ }
+
+ jRecorderSettings = settings;
+
+
+
+ if($.browser.msie && Number($.browser.version) <= 8) {
+ var objStr = '<object name="'+ settings['recorder_name'] +'" id="' + settings['recorder_id'] + '" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="'+ settings['rec_width'] +'" height="'+ settings['rec_height']+'"></object>';
+
+ var paramStr = [
+ '<param name="movie" value="'+ settings['swf_path'] + '?host=' + settings['host'] + '" />',
+
+ '<param name="allowScriptAccess" value="always" />',
+ '<param name="bgcolor" value="' + settings['bgcolor'] + '" />',
+ '<param name="wmode" value="' + settings['wmode'] + '" />'
+ ];
+
+ htmlObj = document.createElement(objStr);
+ for(var i=0; i < paramStr.length; i++) {
+ htmlObj.appendChild(document.createElement(paramStr[i]));
+ }
+
+
+ //var divStr = ' <div id="'+ settings['recorderlayout_id'] +'" style="position:absolute;top:0px;left:0px;z-index:-1" ></div>';
+ //var divObj = document.createElement(divStr);
+
+
+ } else {
+ var createParam = function(el, n, v) {
+ var p = document.createElement("param");
+ p.setAttribute("name", n);
+ p.setAttribute("value", v);
+ el.appendChild(p);
+ };
+
+ htmlObj = document.createElement("object");
+ htmlObj.setAttribute("id", settings['recorder_id'] );
+ htmlObj.setAttribute("name", settings['recorder_name'] );
+ htmlObj.setAttribute("data", settings['swf_path'] + '?host=' + settings['host'] );
+ htmlObj.setAttribute("type", "application/x-shockwave-flash");
+ htmlObj.setAttribute("width", settings['rec_width']); // Non-zero
+ htmlObj.setAttribute("height", settings['rec_height']); // Non-zero
+
+ createParam(htmlObj, "allowscriptaccess", "always");
+ createParam(htmlObj, "bgcolor", settings['bgcolor']);
+ createParam(htmlObj, "wmode", settings['wmode'] );
+
+
+
+
+ }
+
+
+ var divObj = document.createElement("div");
+
+ divObj.setAttribute("id", settings['recorderlayout_id']);
+ divObj.setAttribute("style", "position:absolute;top:"+ settings['rec_top'] +";left:"+ settings['rec_left'] +";z-index:-1");
+
+ divObj.appendChild(htmlObj);
+
+
+ element.append(divObj);
+
+
+
+
+
+
+
+
+ };
+
+ //function call to start a recording
+ $.jRecorder.record = function(max_time){
+
+
+ //change z-index to make it top
+ $( '#' + jRecorderSettings['recorderlayout_id'] ).css('z-index', 1000);
+ getFlashMovie(jRecorderSettings['recorder_name']).jStartRecording(max_time);
+
+
+
+ }
+
+ //function call to stop recording
+ $.jRecorder.stop = function(){
+
+ getFlashMovie(jRecorderSettings['recorder_name']).jStopRecording();
+
+ }
+
+ //function call to send wav data to server url from the init configuration
+ $.jRecorder.sendData = function(){
+
+ getFlashMovie(jRecorderSettings['recorder_name']).jSendFileToServer();
+
+ }
+
+ $.jRecorder.callback_started_recording = function(){
+
+
+ jRecorderSettings['callback_started_recording']();
+
+ }
+
+
+ $.jRecorder.callback_finished_recording = function(){
+
+ jRecorderSettings['callback_finished_recording']();
+
+ }
+
+ $.jRecorder.callback_error_recording = function(){
+
+ jRecorderSettings['callback_error_recording']();
+
+ }
+
+ $.jRecorder.callback_stopped_recording = function(){
+
+ jRecorderSettings['callback_stopped_recording']();
+ }
+
+
+ $.jRecorder.callback_finished_sending = function(){
+
+ jRecorderSettings['callback_finished_sending']();
+
+ }
+
+ $.jRecorder.callback_activityLevel = function(level){
+
+ jRecorderSettings['callback_activityLevel'](level);
+
+ }
+
+ $.jRecorder.callback_activityTime = function(time){
+
+ //put back flash while recording
+ $( '#' + jRecorderSettings['recorderlayout_id'] ).css('z-index', -1);
+
+ jRecorderSettings['callback_activityTime'](time);
+
+ }
+
+
+
+
+ //function to return flash object from name
+ function getFlashMovie(movieName) {
+ var isIE = navigator.appName.indexOf("Microsoft") != -1;
+ return (isIE) ? window[movieName] : document[movieName];
+ }
+
+
+
+})(jQuery);
+
+
+
View
BIN jRecorder.swf
Binary file not shown.
View
BIN jRecorder.swf.bu
Binary file not shown.
View
36 log_file.log
@@ -0,0 +1,36 @@
+ffmpeg version 0.8.3-4:0.8.3-0ubuntu0.12.04.1, Copyright (c) 2000-2012 the Libav developers
+ built on Jun 12 2012 16:52:09 with gcc 4.6.3
+*** THIS PROGRAM IS DEPRECATED ***
+This program is only provided for compatibility and will be removed in a future release. Please use avconv instead.
+[wav @ 0x14417a0] max_analyze_duration reached
+Input #0, wav, from 'watson.wav':
+ Duration: 00:00:10.86, bitrate: 705 kb/s
+ Stream #0.0: Audio: pcm_s16le, 44100 Hz, 1 channels, s16, 705 kb/s
+The bitrate parameter is set too low.It takes bits/s as argument, not kbits/s
+Output #0, wav, to 'watson-audio.wav':
+ Metadata:
+ encoder : Lavf53.21.0
+ Stream #0.0: Audio: pcm_s16le, 8000 Hz, 1 channels, s16, 128 kb/s
+Stream mapping:
+ Stream #0.0 -> #0.0
+Press ctrl-c to stop encoding
+size= 170kB time=10.87 bitrate= 128.0kbits/s
+video:0kB audio:170kB global headers:0kB muxing overhead 0.026459%
+ffmpeg version 0.8.3-4:0.8.3-0ubuntu0.12.04.1, Copyright (c) 2000-2012 the Libav developers
+ built on Jun 12 2012 16:52:09 with gcc 4.6.3
+*** THIS PROGRAM IS DEPRECATED ***
+This program is only provided for compatibility and will be removed in a future release. Please use avconv instead.
+[wav @ 0x1c3d7a0] max_analyze_duration reached
+Input #0, wav, from 'watson.wav':
+ Duration: 00:00:05.71, bitrate: 705 kb/s
+ Stream #0.0: Audio: pcm_s16le, 44100 Hz, 1 channels, s16, 705 kb/s
+The bitrate parameter is set too low.It takes bits/s as argument, not kbits/s
+Output #0, wav, to 'watson-audio.wav':
+ Metadata:
+ encoder : Lavf53.21.0
+ Stream #0.0: Audio: pcm_s16le, 8000 Hz, 1 channels, s16, 128 kb/s
+Stream mapping:
+ Stream #0.0 -> #0.0
+Press ctrl-c to stop encoding
+size= 89kB time=5.71 bitrate= 128.1kbits/s
+video:0kB audio:89kB global headers:0kB muxing overhead 0.050343%
View
87 mictest.php
@@ -0,0 +1,87 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
+ <script>
+ var localMediaStream;
+ var recorder;
+ var video;
+ var audio;
+
+ function hasGetUserMedia() {
+ // Note: Opera is unprefixed.
+ return !!(navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia);
+ }
+
+ function onFailSoHard (e) {
+ console.log('Reeeejected!', e);
+ };
+
+ function initializeMediaElements () {
+ console.log('initializing...');
+ window.URL = window.URL || window.webkitURL;
+ navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
+ video = document.querySelector('video');
+ audio = document.querySelector('audio');
+ navigator.getUserMedia({video: true, audio: true, toString: function() {return "video,audio";}}, function (stream) {
+ audio.src = window.URL.createObjectURL(stream);
+ audio.play();
+ video.src = window.URL.createObjectURL(stream);
+ video.play();
+ localMediaStream = stream;
+ console.log('camera and mic are setup');
+ }, onFailSoHard);
+ }
+
+ function startRecording (){
+ console.log('recording video and audio to local blob...');
+ console.log(localMediaStream);
+ recorder = localMediaStream.record();
+ }
+
+ function stopRecording (){
+ localMediaStream.stop();
+ /*audio.src = window.URL.createObjectURL(localMediaStream);
+ video.src = window.URL.createObjectURL(localMediaStream);
+ audio.play();
+ video.play();
+ console.log('playing from the local blob');
+ */
+ recorder.getRecordedData(function(blob) {
+ // Upload blob using XHR2.
+ audio.src = window.URL.createObjectURL(blob);
+ video.src = window.URL.createObjectURL(blob);
+ document.getElementById('audiodata').innerHTML = blob;
+ audio.play();
+ video.play();
+ console.log('playing from the local blob');
+ console.log(blob);
+ });
+ }
+
+ $(document).ready(function() {
+ // Handler for .ready() called.
+ if (hasGetUserMedia()) {
+ console.log('Good to go! we have support for getUserMedia API!');
+ initializeMediaElements();
+ } else {
+ alert('getUserMedia() is not supported in your browser');
+ }
+ });
+
+ </script>
+</head>
+<body>
+ <video style="width:320px;height:240px;"></video>
+ <audio></audio>
+ <div id="audiodata"></div>
+ <input onclick="startRecording()" type="button" value="start recording" />
+ <input onclick="stopRecording()" type="button" value="stop recording and play" />
+ <!--
+<form enctype="multipart/form-data">
+<input name="file" type="file" />
+<input type="button" value="Upload" />
+</form>
+-->
+</body>
+</html>
View
BIN watson-audio.wav
Binary file not shown.
View
BIN watson.wav
Binary file not shown.

0 comments on commit 7282e2a

Please sign in to comment.