From ec0f90125da03d850f9f07c4ff7540029241a1e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Carlos=20Ra=C3=B1a?= Date: Wed, 4 Apr 2012 13:09:13 +0200 Subject: [PATCH] implement wami record in documents tool --- main/document/document.php | 12 +- main/document/record_audio.php | 206 -------------- main/document/record_audio_wami.php | 199 +++++++++++++ .../{example/client => }/Wami.swf | Bin .../{example/client => }/buttons.png | Bin .../wami-recorder/example/client/basic.html | 44 --- .../wami-recorder/example/client/index.html | 52 ---- .../wami-recorder/example/server/README.txt | 12 - .../example/server/php/record.php | 9 - .../example/server/python/server.py | 53 ---- .../wami-recorder/example/wami-recorder.xml | 9 - .../wami-recorder/{example/client => }/gui.js | 0 main/inc/lib/wami-recorder/index.html | 6 + .../inc/lib/wami-recorder/record_document.php | 72 +++++ .../{example/client => }/recorder.js | 0 .../edu/mit/csail/wami/audio/AuContainer.as | 171 ----------- .../edu/mit/csail/wami/audio/AudioFormat.as | 158 ---------- .../edu/mit/csail/wami/audio/DecodePipe.as | 125 -------- .../edu/mit/csail/wami/audio/EncodePipe.as | 126 -------- .../mit/csail/wami/audio/IAudioContainer.as | 54 ---- .../edu/mit/csail/wami/audio/WaveContainer.as | 131 --------- .../mit/csail/wami/client/FlashSettings.as | 2 - .../src/edu/mit/csail/wami/client/Wami.mxml | 104 ------- .../edu/mit/csail/wami/client/WamiAudio.as | 109 ------- .../edu/mit/csail/wami/client/WamiListener.as | 61 ---- .../edu/mit/csail/wami/client/WamiParams.as | 180 ------------ .../src/edu/mit/csail/wami/play/IPlayer.as | 39 --- .../src/edu/mit/csail/wami/play/WamiPlayer.as | 179 ------------ .../edu/mit/csail/wami/record/ChunkPipe.as | 5 - .../edu/mit/csail/wami/record/IRecorder.as | 49 ---- .../edu/mit/csail/wami/record/MultiPost.as | 111 -------- .../edu/mit/csail/wami/record/SinglePost.as | 159 ----------- .../edu/mit/csail/wami/record/WamiRecorder.as | 269 ------------------ .../src/edu/mit/csail/wami/utils/BytePipe.as | 93 ------ .../src/edu/mit/csail/wami/utils/External.as | 144 ---------- .../src/edu/mit/csail/wami/utils/Pipe.as | 3 - .../edu/mit/csail/wami/utils/StateListener.as | 35 --- main/install/db_main.sql | 7 +- main/install/migrate-db-1.8.8-1.9.0-pre.sql | 5 + 39 files changed, 297 insertions(+), 2696 deletions(-) delete mode 100644 main/document/record_audio.php create mode 100644 main/document/record_audio_wami.php rename main/inc/lib/wami-recorder/{example/client => }/Wami.swf (100%) rename main/inc/lib/wami-recorder/{example/client => }/buttons.png (100%) delete mode 100644 main/inc/lib/wami-recorder/example/client/basic.html delete mode 100644 main/inc/lib/wami-recorder/example/client/index.html delete mode 100644 main/inc/lib/wami-recorder/example/server/README.txt delete mode 100644 main/inc/lib/wami-recorder/example/server/php/record.php delete mode 100644 main/inc/lib/wami-recorder/example/server/python/server.py delete mode 100644 main/inc/lib/wami-recorder/example/wami-recorder.xml rename main/inc/lib/wami-recorder/{example/client => }/gui.js (100%) create mode 100644 main/inc/lib/wami-recorder/index.html create mode 100644 main/inc/lib/wami-recorder/record_document.php rename main/inc/lib/wami-recorder/{example/client => }/recorder.js (100%) delete mode 100644 main/inc/lib/wami-recorder/src/edu/mit/csail/wami/audio/AuContainer.as delete mode 100644 main/inc/lib/wami-recorder/src/edu/mit/csail/wami/audio/AudioFormat.as delete mode 100644 main/inc/lib/wami-recorder/src/edu/mit/csail/wami/audio/DecodePipe.as delete mode 100644 main/inc/lib/wami-recorder/src/edu/mit/csail/wami/audio/EncodePipe.as delete mode 100644 main/inc/lib/wami-recorder/src/edu/mit/csail/wami/audio/IAudioContainer.as delete mode 100644 main/inc/lib/wami-recorder/src/edu/mit/csail/wami/audio/WaveContainer.as delete mode 100644 main/inc/lib/wami-recorder/src/edu/mit/csail/wami/client/FlashSettings.as delete mode 100644 main/inc/lib/wami-recorder/src/edu/mit/csail/wami/client/Wami.mxml delete mode 100644 main/inc/lib/wami-recorder/src/edu/mit/csail/wami/client/WamiAudio.as delete mode 100644 main/inc/lib/wami-recorder/src/edu/mit/csail/wami/client/WamiListener.as delete mode 100644 main/inc/lib/wami-recorder/src/edu/mit/csail/wami/client/WamiParams.as delete mode 100644 main/inc/lib/wami-recorder/src/edu/mit/csail/wami/play/IPlayer.as delete mode 100644 main/inc/lib/wami-recorder/src/edu/mit/csail/wami/play/WamiPlayer.as delete mode 100644 main/inc/lib/wami-recorder/src/edu/mit/csail/wami/record/ChunkPipe.as delete mode 100644 main/inc/lib/wami-recorder/src/edu/mit/csail/wami/record/IRecorder.as delete mode 100644 main/inc/lib/wami-recorder/src/edu/mit/csail/wami/record/MultiPost.as delete mode 100644 main/inc/lib/wami-recorder/src/edu/mit/csail/wami/record/SinglePost.as delete mode 100644 main/inc/lib/wami-recorder/src/edu/mit/csail/wami/record/WamiRecorder.as delete mode 100644 main/inc/lib/wami-recorder/src/edu/mit/csail/wami/utils/BytePipe.as delete mode 100644 main/inc/lib/wami-recorder/src/edu/mit/csail/wami/utils/External.as delete mode 100644 main/inc/lib/wami-recorder/src/edu/mit/csail/wami/utils/Pipe.as delete mode 100644 main/inc/lib/wami-recorder/src/edu/mit/csail/wami/utils/StateListener.as diff --git a/main/document/document.php b/main/document/document.php index 5c7c796713..2922f089d7 100644 --- a/main/document/document.php +++ b/main/document/document.php @@ -1073,7 +1073,7 @@ if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_fold @@ -1081,7 +1081,15 @@ if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_fold + + + diff --git a/main/document/record_audio.php b/main/document/record_audio.php deleted file mode 100644 index 36dae64336..0000000000 --- a/main/document/record_audio.php +++ /dev/null @@ -1,206 +0,0 @@ - "../group/group_space.php?gidReq=".$_SESSION['_gid'], "name" => get_lang('GroupSpace')); - $noPHP_SELF = true; - $to_group_id = $_SESSION['_gid']; - $group = GroupManager :: get_group_properties($to_group_id); - $path = explode('/', $dir); - if ('/'.$path[1] != $group['directory']) { - api_not_allowed(true); - } -} - -$interbreadcrumb[] = array ("url" => "./document.php?id=".$document_id.$req_gid, "name" => get_lang('Documents')); - -if (!$is_allowed_in_course) { - api_not_allowed(true); -} - -if (!($is_allowed_to_edit || $_SESSION['group_member_with_upload_rights'] || is_my_shared_folder(api_get_user_id(), Security::remove_XSS($dir),api_get_session_id()))) { - api_not_allowed(true); -} - - -/* Header */ -event_access_tool(TOOL_DOCUMENT); - -$display_dir = $dir; -if (isset ($group)) { - $display_dir = explode('/', $dir); - unset ($display_dir[0]); - unset ($display_dir[1]); - $display_dir = implode('/', $display_dir); -} - -// Interbreadcrumb for the current directory root path -$counter = 0; -if (isset($document_data['parents'])) { - foreach($document_data['parents'] as $document_sub_data) { - //fixing double group folder in breadcrumb - if (api_get_group_id()) { - if ($counter == 0) { - $counter++; - continue; - } - } - $interbreadcrumb[] = array('url' => $document_sub_data['document_url'], 'name' => $document_sub_data['title']); - $counter++; - } -} -Display :: display_header($nameTools, 'Doc'); - -echo '
'; - echo ''.Display::return_icon('back.png',get_lang('BackTo').' '.get_lang('DocumentsOverview'),'',ICON_SIZE_MEDIUM).''; -echo '
'; - -?> - - -'; - -Display::display_icon('microphone.png', get_lang('PressRecordButton'),'','128'); -echo '
'; -echo ''; - //echo ''; // default true - // echo ''; //you can save in local computer | (default true) - //echo ''; // default true - //echo ''; // it displays the audiometer | (default true) - echo ''; // default false - //echo ''; // default #FFFFFF - //echo ''; - //echo ''; - echo '';// ImaADPCM (more speed), Speex (more compression)|(default Speex) - //echo '';//Quality for ImaADPCM (low 8000, medium 11025, normal 22050, hight 44100) OR Quality for Speex (low 8000, medium 16000, normal 32000, hight 44100) | (default 44100) - //echo ''; - //echo '';//load a file |(default "") - -echo ''; - -echo '
'; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; -echo '
'; - -echo ''; -Display :: display_footer(); \ No newline at end of file diff --git a/main/document/record_audio_wami.php b/main/document/record_audio_wami.php new file mode 100644 index 0000000000..f2e40814c8 --- /dev/null +++ b/main/document/record_audio_wami.php @@ -0,0 +1,199 @@ + "../group/group_space.php?gidReq=".$_SESSION['_gid'], "name" => get_lang('GroupSpace')); + $noPHP_SELF = true; + $to_group_id = $_SESSION['_gid']; + $group = GroupManager :: get_group_properties($to_group_id); + $path = explode('/', $dir); + if ('/'.$path[1] != $group['directory']) { + api_not_allowed(true); + } +} + +$interbreadcrumb[] = array ("url" => "./document.php?id=".$document_id.$req_gid, "name" => get_lang('Documents')); + +if (!$is_allowed_in_course) { + api_not_allowed(true); +} + +if (!($is_allowed_to_edit || $_SESSION['group_member_with_upload_rights'] || is_my_shared_folder(api_get_user_id(), Security::remove_XSS($dir),api_get_session_id()))) { + api_not_allowed(true); +} + + +/* Header */ +event_access_tool(TOOL_DOCUMENT); + +$display_dir = $dir; +if (isset ($group)) { + $display_dir = explode('/', $dir); + unset ($display_dir[0]); + unset ($display_dir[1]); + $display_dir = implode('/', $display_dir); +} + +// Interbreadcrumb for the current directory root path +$counter = 0; +if (isset($document_data['parents'])) { + foreach($document_data['parents'] as $document_sub_data) { + //fixing double group folder in breadcrumb + if (api_get_group_id()) { + if ($counter == 0) { + $counter++; + continue; + } + } + $interbreadcrumb[] = array('url' => $document_sub_data['document_url'], 'name' => $document_sub_data['title']); + $counter++; + } +} + +Display :: display_header($nameTools, 'Doc'); +echo '
'; + echo ''.Display::return_icon('back.png',get_lang('BackTo').' '.get_lang('DocumentsOverview'),'',ICON_SIZE_MEDIUM).''; +echo '
'; + + +?> + + + + + + + + + + + +
+
+ + +
+ + + - - - - - - - - - - - - - - - -
-
- - diff --git a/main/inc/lib/wami-recorder/example/client/index.html b/main/inc/lib/wami-recorder/example/client/index.html deleted file mode 100644 index 5fdc5477a1..0000000000 --- a/main/inc/lib/wami-recorder/example/client/index.html +++ /dev/null @@ -1,52 +0,0 @@ - - - - - - - - - - - - - - - - -
- - -
- Right-click to Download

index.html
- Wami.swf
- buttons.png
- recorder.js
- gui.js
-
- - diff --git a/main/inc/lib/wami-recorder/example/server/README.txt b/main/inc/lib/wami-recorder/example/server/README.txt deleted file mode 100644 index e4440868fa..0000000000 --- a/main/inc/lib/wami-recorder/example/server/README.txt +++ /dev/null @@ -1,12 +0,0 @@ -Each directory (or sub-directory of 'gae') contains an example server -in a particular language designed to handle audio incoming from the -Wami recorder. - -The PHP example requires the configuration of a PHP-enabled -web-server, while the python server can be run on any machine with -python installed. - -If you do not wish to host your own server, you can try out the Google -App Engine (GAE) examples. The GAE python example stores data in a -"blobstore", for which Google provides a handy web-based management -console. diff --git a/main/inc/lib/wami-recorder/example/server/php/record.php b/main/inc/lib/wami-recorder/example/server/php/record.php deleted file mode 100644 index 7fb6856231..0000000000 --- a/main/inc/lib/wami-recorder/example/server/php/record.php +++ /dev/null @@ -1,9 +0,0 @@ - \ No newline at end of file diff --git a/main/inc/lib/wami-recorder/example/server/python/server.py b/main/inc/lib/wami-recorder/example/server/python/server.py deleted file mode 100644 index c869d62f0e..0000000000 --- a/main/inc/lib/wami-recorder/example/server/python/server.py +++ /dev/null @@ -1,53 +0,0 @@ -# Run from the commandline: -# -# python server.py -# POST audio to http://localhost:9000 -# GET audio from http://localhost:9000 -# -# A simple server to collect audio using python. To be more secure, -# you might want to check the file names and place size restrictions -# on the incoming data. - -import cgi -from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer - -class WamiHandler(BaseHTTPRequestHandler): - dirname = "/tmp/" - - def do_GET(self): - f = open(self.get_name()) - self.send_response(200) - self.send_header('content-type','audio/x-wav') - self.end_headers() - self.wfile.write(f.read()) - f.close() - - def do_POST(self): - f = open(self.get_name(), "wb") - # Note that python's HTTPServer doesn't support chunked transfer. - # Thus, it requires a content-length. - length = int(self.headers.getheader('content-length')) - print "POST of length " + str(length) - f.write(self.rfile.read(length)) - f.close(); - - def get_name(self): - filename = 'output.wav'; - qs = self.path.split('?',1); - if len(qs) == 2: - params = cgi.parse_qs(qs[1]) - if params['name']: - filename = params['name'][0]; - return WamiHandler.dirname + filename - -def main(): - try: - server = HTTPServer(('', 9000), WamiHandler) - print 'Started server...' - server.serve_forever() - except KeyboardInterrupt: - print 'Stopping server' - server.socket.close() - -if __name__ == '__main__': - main() diff --git a/main/inc/lib/wami-recorder/example/wami-recorder.xml b/main/inc/lib/wami-recorder/example/wami-recorder.xml deleted file mode 100644 index 6630b5b54b..0000000000 --- a/main/inc/lib/wami-recorder/example/wami-recorder.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - diff --git a/main/inc/lib/wami-recorder/example/client/gui.js b/main/inc/lib/wami-recorder/gui.js similarity index 100% rename from main/inc/lib/wami-recorder/example/client/gui.js rename to main/inc/lib/wami-recorder/gui.js diff --git a/main/inc/lib/wami-recorder/index.html b/main/inc/lib/wami-recorder/index.html new file mode 100644 index 0000000000..aa7b9c934b --- /dev/null +++ b/main/inc/lib/wami-recorder/index.html @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/main/inc/lib/wami-recorder/record_document.php b/main/inc/lib/wami-recorder/record_document.php new file mode 100644 index 0000000000..26374a7493 --- /dev/null +++ b/main/inc/lib/wami-recorder/record_document.php @@ -0,0 +1,72 @@ + \ No newline at end of file diff --git a/main/inc/lib/wami-recorder/example/client/recorder.js b/main/inc/lib/wami-recorder/recorder.js similarity index 100% rename from main/inc/lib/wami-recorder/example/client/recorder.js rename to main/inc/lib/wami-recorder/recorder.js diff --git a/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/audio/AuContainer.as b/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/audio/AuContainer.as deleted file mode 100644 index 7f53fdc4e9..0000000000 --- a/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/audio/AuContainer.as +++ /dev/null @@ -1,171 +0,0 @@ -/* -* Copyright (c) 2011 -* Spoken Language Systems Group -* MIT Computer Science and Artificial Intelligence Laboratory -* Massachusetts Institute of Technology -* -* Permission is hereby granted, free of charge, to any person -* obtaining a copy of this software and associated documentation -* files (the "Software"), to deal in the Software without -* restriction, including without limitation the rights to use, copy, -* modify, merge, publish, distribute, sublicense, and/or sell copies -* of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be -* included in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -*/ -package edu.mit.csail.wami.audio -{ - import edu.mit.csail.wami.utils.External; - - import flash.utils.ByteArray; - import flash.utils.Endian; - - /** - * This container is better for streaming, because it explicitly - * says what to do when the length of the audio is unknown. It's typically - * associated with mu-law compression (which wouldn't be too hard too implement) - * but here we're using linear PCM. - */ - public class AuContainer implements IAudioContainer - { - public function isLengthRequired():Boolean { - return false; - } - - public function toByteArray(format:AudioFormat, length:int = -1):ByteArray - { - var dataLength:uint = 0xffffffff; - if (length > -1) - { - dataLength = length; - } - - if (format.endian != Endian.BIG_ENDIAN) - { - throw new Error("AU is a container for big endian data"); - } - // http://en.wikipedia.org/wiki/Au_file_format - var header:ByteArray = new ByteArray(); - header.endian = format.endian; - header.writeUTFBytes(".snd"); - header.writeInt(24); // Data offset - header.writeInt(dataLength); - - var bits:uint = getEncodingFromBits(format); - header.writeInt(bits); - header.writeInt(format.rate); - header.writeInt(format.channels); - header.position = 0; - External.debugBytes(header); - return header; - } - - private function getEncodingFromBits(format:AudioFormat):uint - { - if (format.bits == 16) - { - return 3; - } - else if (format.bits == 24) - { - return 4; - } - else if (format.bits == 32) - { - return 5; - } - - throw new Error("Bits not supported"); - } - - private function getBitsFromEncoding(encoding:uint):uint - { - if (encoding == 3) - { - return 16; - } - else if (encoding == 4) - { - return 24; - } - else if (encoding == 5) - { - return 32; - } - - throw new Error("Encoding not supported: " + encoding); - } - - public function fromByteArray(header:ByteArray):AudioFormat - { - if (header.bytesAvailable < 24) - { - return notAu(header, "Header not yet long enough for Au"); - } - - var b:ByteArray = new ByteArray(); - header.readBytes(b, 0, 24); - External.debugBytes(b); - header.position = 0; - - header.endian = Endian.BIG_ENDIAN; // Header is big-endian - - var magic:String = header.readUTFBytes(4); - if (magic != ".snd") - { - return notAu(header, "Not an AU header, first bytes should be .snd"); - } - - var dataOffset:uint = header.readInt(); - var dataLength:uint = header.readInt(); - - if (header.bytesAvailable < dataOffset - 12) - { - return notAu(header, "Header of length " + header.bytesAvailable + " not long enough yet to include offset of length " + dataOffset); - } - - var encoding:uint = header.readInt(); - - var bits:uint; - try { - bits = getBitsFromEncoding(encoding); - } catch (e:Error) { - return notAu(header, e.message); - } - - var rate:uint = header.readInt(); - var channels:uint = header.readInt(); - - header.position = dataOffset; - - var format:AudioFormat; - try - { - format = new AudioFormat(rate, channels, bits, Endian.BIG_ENDIAN); - } catch (e:Error) - { - return notAu(header, e.message); - } - - return format; - } - - private function notAu(header:ByteArray, msg:String):AudioFormat - { - External.debug("Not Au: " + msg); - header.position = 0; - return null; - } - } -} \ No newline at end of file diff --git a/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/audio/AudioFormat.as b/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/audio/AudioFormat.as deleted file mode 100644 index eebff7d377..0000000000 --- a/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/audio/AudioFormat.as +++ /dev/null @@ -1,158 +0,0 @@ -/* -* Copyright (c) 2011 -* Spoken Language Systems Group -* MIT Computer Science and Artificial Intelligence Laboratory -* Massachusetts Institute of Technology -* -* Permission is hereby granted, free of charge, to any person -* obtaining a copy of this software and associated documentation -* files (the "Software"), to deal in the Software without -* restriction, including without limitation the rights to use, copy, -* modify, merge, publish, distribute, sublicense, and/or sell copies -* of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be -* included in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -*/ -package edu.mit.csail.wami.audio -{ - import flash.utils.Endian; - - /** - * This class keeps track of all the information that defines the - * audio format independent of the actual audio container - * (e.g. .wav or .au) - */ - public class AudioFormat - { - // Allow 8 and 16 kHz as well. - public static var allrates:Boolean = false; - - public var channels:uint; - public var rate:uint; - public var bits:uint; - public var endian:String; - - public function AudioFormat(rate:uint, channels:uint, bits:uint, endian:String) - { - this.rate = rate; - this.channels = channels; - this.endian = endian; - this.bits = bits; - - validate(); - } - - // flash.media.Microphone quasi-rounds sample rates in kHz - public static function toRoundedRate(rate:uint):uint - { - if (rate == 5512) - { - return 5; - } - else if (rate == 8000) - { - return 8; - } - else if (rate == 11025) - { - return 11; - } - else if (rate == 16000) - { - return 16; - } - else if (rate == 22050) - { - return 22; - } - else if (rate == 44100) - { - return 44; - } - - throw new Error("Unsupported sample rate in Hz: " + rate); - } - - - public static function fromRoundedRate(rate:uint):uint - { - if (rate == 5) - { - return 5512; - } - else if (rate == 8) - { - return 8000; - } - else if (rate == 11) - { - return 11025; - } - else if (rate == 16) - { - return 16000; - } - else if (rate == 22) - { - return 22050; - } - else if (rate == 44) - { - return 44100; - } - - throw new Error("Unsupported sample rate rounded in kHz: " + rate); - } - - public function validate():void - { - if (bits != 8 && bits != 16 && bits != 32) - { - throw new Error("Unsupported number of bits per sample: " + bits); - } - - if (channels != 1 && channels != 2) - { - throw new Error("Unsupported number of channels: " + channels); - } - - if (endian != Endian.BIG_ENDIAN && endian != Endian.LITTLE_ENDIAN) - { - throw new Error("Unsupported endian type: " + endian); - } - - var msg:String = ""; - if (rate < 100) - { - throw new Error("Rate should be in Hz"); - } - else if (rate != 5512 && rate != 8000 && rate != 11025 && rate != 16000 && rate != 22050 && rate != 44100) - { - msg = "Sample rate of " + rate + " is not supported."; - msg += " See flash.media.Microphone documentation." - throw new Error(msg); - } - else if (!allrates && (rate == 8000 || rate == 16000 || rate == 11025)) { - msg = "8kHz and 16kHz are supported for recording but not playback. 11kHz doesn't work in Ubuntu."; - msg += " Enable all rates via a parameter passed into the Flash." - throw new Error(msg); - } - } - - public function toString():String - { - return "Rate: " + rate + " Channels " + channels + " Bits: " + bits + " Endian: " + endian; - } - } -} \ No newline at end of file diff --git a/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/audio/DecodePipe.as b/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/audio/DecodePipe.as deleted file mode 100644 index bd462fec16..0000000000 --- a/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/audio/DecodePipe.as +++ /dev/null @@ -1,125 +0,0 @@ -/* -* Copyright (c) 2011 -* Spoken Language Systems Group -* MIT Computer Science and Artificial Intelligence Laboratory -* Massachusetts Institute of Technology -* -* Permission is hereby granted, free of charge, to any person -* obtaining a copy of this software and associated documentation -* files (the "Software"), to deal in the Software without -* restriction, including without limitation the rights to use, copy, -* modify, merge, publish, distribute, sublicense, and/or sell copies -* of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be -* included in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -*/ -package edu.mit.csail.wami.audio -{ - import edu.mit.csail.wami.audio.AudioFormat; - import edu.mit.csail.wami.audio.IAudioContainer; - import edu.mit.csail.wami.utils.External; - import edu.mit.csail.wami.utils.Pipe; - - import flash.utils.ByteArray; - import flash.utils.Endian; - - /** - * Convert WAVE data coming in to the float-based format flash uses. - */ - public class DecodePipe extends Pipe - { - private var format:AudioFormat; - private var header:ByteArray = new ByteArray(); - private var containers:Vector.; - - public function DecodePipe(containers:Vector.) { - if (containers.length == 0) { - throw new Error("Must have at least one container."); - } - this.containers = containers; - } - - override public function write(bytes:ByteArray):void - { - if (format == null) - { - // Try to get header by parsing from each container - bytes.readBytes(header, header.length, bytes.length); - for each (var container:IAudioContainer in containers) { - format = container.fromByteArray(header); - if (format != null) { - // Put the leftover bytes back - bytes = new ByteArray(); - header.readBytes(bytes); - External.debug("Format: " + format); - break; - } - } - } - - if (format != null && bytes.bytesAvailable) - { - bytes.endian = format.endian; - super.write(decode(bytes)); - } - } - - private function decode(bytes:ByteArray):ByteArray - { - var decoded:ByteArray = new ByteArray(); - while (bytes.bytesAvailable) - { - var sample1:Number = getSample(bytes); - var sample2:Number = sample1; - if (format.channels == 2) - { - sample2 = getSample(bytes); - } - - // cheap way to upsample - var repeat:uint = 44100 / format.rate; - while (repeat-- > 0) { - decoded.writeFloat(sample1); - decoded.writeFloat(sample2); - } - } - decoded.position = 0; - return decoded; - } - - private function getSample(bytes:ByteArray):Number - { - var sample:Number; - - if (format.bits == 8) - { - sample = bytes.readByte()/0x7f; - } - else if (format.bits == 16) - { - sample = bytes.readShort()/0x7fff; - } - else if (format.bits == 32) - { - sample = bytes.readInt()/0x7fffffff; - } - else - { - throw new Error("Unsupported bits per sample: " + format.bits); - } - - return sample; - } - } -} \ No newline at end of file diff --git a/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/audio/EncodePipe.as b/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/audio/EncodePipe.as deleted file mode 100644 index 2c70bad9c9..0000000000 --- a/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/audio/EncodePipe.as +++ /dev/null @@ -1,126 +0,0 @@ -/* -* Copyright (c) 2011 -* Spoken Language Systems Group -* MIT Computer Science and Artificial Intelligence Laboratory -* Massachusetts Institute of Technology -* -* Permission is hereby granted, free of charge, to any person -* obtaining a copy of this software and associated documentation -* files (the "Software"), to deal in the Software without -* restriction, including without limitation the rights to use, copy, -* modify, merge, publish, distribute, sublicense, and/or sell copies -* of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be -* included in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -*/ -package edu.mit.csail.wami.audio -{ - import edu.mit.csail.wami.audio.AudioFormat; - import edu.mit.csail.wami.audio.IAudioContainer; - import edu.mit.csail.wami.utils.Pipe; - - import flash.utils.ByteArray; - - /** - * Convert float format to raw audio accoring to the audio format passed in. - */ - public class EncodePipe extends Pipe - { - private var format:AudioFormat; - private var container:IAudioContainer; - - // Buffer if container requires length. In this case, - // we cannot write the data to the sink until the very end. - private var buffer:ByteArray; - private var headerWritten:Boolean; - - function EncodePipe(format:AudioFormat, container:IAudioContainer) - { - this.format = format; - this.container = container; - this.buffer = new ByteArray(); - headerWritten = false; - } - - override public function write(bytes:ByteArray):void - { - var transcoded:ByteArray = new ByteArray(); - transcoded.endian = format.endian; - - while (bytes.bytesAvailable >= 4) - { - var sample:int; - if (format.bits == 16) - { - sample = bytes.readFloat()*0x7fff; - transcoded.writeShort(sample); - if (format.channels == 2) - { - transcoded.writeShort(sample); - } - } - else if (format.bits == 32) - { - sample = bytes.readFloat()*0x7fffffff; - transcoded.writeInt(sample); - if (format.channels == 2) - { - transcoded.writeInt(sample); - } - } - else - { - throw new Error("Unsupported bits per sample: " + format.bits); - } - } - transcoded.position = 0; - handleEncoded(transcoded); - } - - private function handleEncoded(bytes:ByteArray):void { - if (container == null) { - // No container, just stream it on - super.write(bytes); - return; - } - - if (container.isLengthRequired()) - { - buffer.writeBytes(bytes, bytes.position, bytes.bytesAvailable); - return; - } - - if (!headerWritten) - { - var header:ByteArray = container.toByteArray(format); - super.write(header); - headerWritten = true; - } - super.write(bytes); - } - - override public function close():void - { - if (container != null && container.isLengthRequired()) - { - // Write the audio (including the header). - buffer.position = 0; - super.write(container.toByteArray(format, buffer.length)); - super.write(buffer); - } - - super.close(); - } - } -} \ No newline at end of file diff --git a/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/audio/IAudioContainer.as b/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/audio/IAudioContainer.as deleted file mode 100644 index 7cf8909109..0000000000 --- a/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/audio/IAudioContainer.as +++ /dev/null @@ -1,54 +0,0 @@ -/* -* Copyright (c) 2011 -* Spoken Language Systems Group -* MIT Computer Science and Artificial Intelligence Laboratory -* Massachusetts Institute of Technology -* -* Permission is hereby granted, free of charge, to any person -* obtaining a copy of this software and associated documentation -* files (the "Software"), to deal in the Software without -* restriction, including without limitation the rights to use, copy, -* modify, merge, publish, distribute, sublicense, and/or sell copies -* of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be -* included in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -*/ -package edu.mit.csail.wami.audio -{ - import flash.utils.ByteArray; - - /** - * There are a number of ways to store raw audio. WAV is a container from - * Microsoft. AU is a container from Sun Microsystems. This interface - * helps us separate the container format from the audio format itself. - */ - public interface IAudioContainer - { - function toByteArray(format:AudioFormat, length:int = -1):ByteArray; - - /** - * If successful, the position is left at the first byte after - * the header. If the bytes do not represent the expected container - * header null is returned and the position is returned to 0. - */ - function fromByteArray(bytes:ByteArray):AudioFormat; - - /** - * Some containers (e.g. WAV) require the length of the data to be specified, - * and thus are not amenable to streaming. Others (e.g. AU) have well - * defined ways of dealing with data of unknown length. - */ - function isLengthRequired():Boolean; - } -} \ No newline at end of file diff --git a/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/audio/WaveContainer.as b/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/audio/WaveContainer.as deleted file mode 100644 index cb3995c968..0000000000 --- a/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/audio/WaveContainer.as +++ /dev/null @@ -1,131 +0,0 @@ -/* -* Copyright (c) 2011 -* Spoken Language Systems Group -* MIT Computer Science and Artificial Intelligence Laboratory -* Massachusetts Institute of Technology -* -* Permission is hereby granted, free of charge, to any person -* obtaining a copy of this software and associated documentation -* files (the "Software"), to deal in the Software without -* restriction, including without limitation the rights to use, copy, -* modify, merge, publish, distribute, sublicense, and/or sell copies -* of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be -* included in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -*/ -package edu.mit.csail.wami.audio -{ - import edu.mit.csail.wami.utils.External; - - import flash.utils.ByteArray; - import flash.utils.Endian; - - /** - * This class builds a WAVE header formt the audio format. - */ - public class WaveContainer implements IAudioContainer - { - public function isLengthRequired():Boolean { - return true; - } - - public function toByteArray(audioFormat:AudioFormat, length:int = -1):ByteArray - { - // https://ccrma.stanford.edu/courses/422/projects/WaveFormat/ - var id:String = (audioFormat.endian == Endian.LITTLE_ENDIAN) ? "RIFF" : "RIFX"; - var bytesPerSample:uint = audioFormat.channels*audioFormat.bits/8; - - var header:ByteArray = new ByteArray(); - - // Little-endian is generally the way to go for WAVs - header.endian = Endian.LITTLE_ENDIAN; - header.writeUTFBytes(id); - header.writeInt(length > 0 ? 36 + length : 0); - header.writeUTFBytes("WAVE"); - header.writeUTFBytes("fmt "); - header.writeInt(16); - header.writeShort(1); - header.writeShort(audioFormat.channels); - header.writeInt(audioFormat.rate); - header.writeInt(audioFormat.rate*bytesPerSample); - header.writeShort(bytesPerSample); - header.writeShort(audioFormat.bits); - header.writeUTFBytes('data'); - header.writeInt(length); - header.position = 0; - return header; - } - - public function fromByteArray(header:ByteArray):AudioFormat - { - if (header.bytesAvailable < 44) { - var msg:String = "This header is not yet long enough "; - msg += "(need 44 bytes only have " + header.bytesAvailable + ")." - return notWav(header, msg); - } - - var endian:String = Endian.LITTLE_ENDIAN; - var chunkID:String = header.readUTFBytes(4); - if (chunkID == "RIFX") - { - endian = Endian.BIG_ENDIAN; - } - else if (chunkID != "RIFF") - { - return notWav(header, "Does not look like a WAVE header: " + chunkID); - } - - header.endian = Endian.LITTLE_ENDIAN; // Header is little-endian - var totalLength:uint = header.readInt() + 8; - var waveFmtStr:String = header.readUTFBytes(8); // "WAVEfmt " - if (waveFmtStr != "WAVEfmt ") - { - return notWav(header, "RIFF header, but not a WAV."); - } - var subchunkSize:uint = header.readUnsignedInt(); // 16 - var audioFormat:uint = header.readShort(); // 1 - if (audioFormat != 1) { - return notWav(header, "Currently we only support linear PCM"); - } - var channels:uint = header.readShort(); - var rate:uint = header.readInt(); - var bps:uint = header.readInt(); - var bytesPerSample:uint = header.readShort(); - var bits:uint = header.readShort(); - var dataStr:String = header.readUTFBytes(4); // "data" - var length:uint = header.readInt(); - - var format:AudioFormat; - try - { - format = new AudioFormat(rate, channels, bits, endian); - } catch (e:Error) - { - return notWav(header, e.message); - } - return format; - } - - /** - * Emit error message for debugging, reset the ByteArray and - * return null. - */ - private function notWav(header:ByteArray, msg:String):AudioFormat - { - External.debug("Not WAV: " + msg); - header.position = 0; - return null; - } - } -} \ No newline at end of file diff --git a/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/client/FlashSettings.as b/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/client/FlashSettings.as deleted file mode 100644 index d6f5f66773..0000000000 --- a/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/client/FlashSettings.as +++ /dev/null @@ -1,2 +0,0 @@ -/* * Copyright (c) 2011 * Spoken Language Systems Group * MIT Computer Science and Artificial Intelligence Laboratory * Massachusetts Institute of Technology * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation * files (the "Software"), to deal in the Software without * restriction, including without limitation the rights to use, copy, * modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ package edu.mit.csail.wami.client { import edu.mit.csail.wami.utils.External; import edu.mit.csail.wami.utils.StateListener; import flash.display.*; import flash.media.*; import flash.system.*; import flash.utils.clearInterval; import flash.utils.setInterval; - /** * Flash settings. This class is largely to get around a shortcoming in * Flash. Although, you can listen for changes to the microphone status, * there appears to be no good way to listen for a status event to tell you * when the settings dialogue has been closed. This hack should suffice. */ public class FlashSettings extends flash.display.MovieClip { private static var MAX_CHECKS:uint = 5; private var theStage:Stage; private var checkSettingsIntervalID:int = 0; private var showedPanel:Boolean = false; private var checkAttempts:int = 0; private var listener:StateListener; public function FlashSettings(s:Stage) { super(); theStage = s; External.addCallback("showSecurity", showSecurity); } // Possible values that settings parameter can take are those of the // string constants documented by Adobe in flash.system.SecurityPanel. public function settingsPanel(settings:String, listener:StateListener):void { this.showedPanel = false; this.checkAttempts = 0; this.listener = listener; flash.system.Security.showSettings(settings); checkSettings(); } private function checkSettings():void { clearInterval(checkSettingsIntervalID); var closed:Boolean = false; if (showingPanel()) { if (!showedPanel) { if (listener) { listener.started(); } } showedPanel = true; } else if (showedPanel) { closed = true; } if (closed) { if (listener) { listener.finished(); } return; } External.debug("check attempts: " + checkAttempts); checkAttempts++; if (checkAttempts > MAX_CHECKS && showedPanel != true) { External.debug("failed"); if (listener) { listener.failed(new Error("Security panel never showed up. Perhaps the browser is zoomed out too far. Try to zoom in and refresh.")); } return; } checkSettingsIntervalID = setInterval(checkSettings, 250); } private function showingPanel():Boolean { var showing:Boolean = false; var dummy:BitmapData; dummy = new BitmapData(1,1); try { // Try to capture the stage: triggers a Security error when the settings dialog box is open // Unfortunately, this is how we have to poll the settings dialogue to know when it closes dummy.draw(theStage); } catch (error:Error) { External.debug("Still not closed, could not capture the stage: " + theStage); showing = true; } dummy.dispose(); dummy = null; return showing; } internal function showSecurity(panel:String, startedCallback:String = null, finishedCallback:String = null, failedCallback:String = null):void { settingsPanel(panel, new WamiListener(startedCallback, finishedCallback, failedCallback)); } } } \ No newline at end of file diff --git a/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/client/Wami.mxml b/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/client/Wami.mxml deleted file mode 100644 index c51d3cafc8..0000000000 --- a/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/client/Wami.mxml +++ /dev/null @@ -1,104 +0,0 @@ - - - - - - - diff --git a/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/client/WamiAudio.as b/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/client/WamiAudio.as deleted file mode 100644 index c9f4b71322..0000000000 --- a/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/client/WamiAudio.as +++ /dev/null @@ -1,109 +0,0 @@ -/* -* Copyright (c) 2011 -* Spoken Language Systems Group -* MIT Computer Science and Artificial Intelligence Laboratory -* Massachusetts Institute of Technology -* -* Permission is hereby granted, free of charge, to any person -* obtaining a copy of this software and associated documentation -* files (the "Software"), to deal in the Software without -* restriction, including without limitation the rights to use, copy, -* modify, merge, publish, distribute, sublicense, and/or sell copies -* of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be -* included in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -*/ -package edu.mit.csail.wami.client -{ - import edu.mit.csail.wami.play.IPlayer; - import edu.mit.csail.wami.play.WamiPlayer; - import edu.mit.csail.wami.record.IRecorder; - import edu.mit.csail.wami.record.WamiRecorder; - import edu.mit.csail.wami.utils.External; - - import flash.display.MovieClip; - - public class WamiAudio extends MovieClip - { - private var recorder:IRecorder; - private var player:IPlayer; - - private var checkSettingsIntervalID:int = 0; - private var checkSettingsInterval:int = 1000; - - function WamiAudio(params:WamiParams) - { - recorder = new WamiRecorder(params.getMicrophone(), params); - player = new WamiPlayer(); - - External.addCallback("startListening", startListening); - External.addCallback("stopListening", stopListening); - External.addCallback("startRecording", startRecording); - External.addCallback("stopRecording",stopRecording); - External.addCallback("getRecordingLevel", getRecordingLevel); - - External.addCallback("startPlaying",startPlaying); - External.addCallback("stopPlaying",stopPlaying); - External.addCallback("getPlayingLevel", getPlayingLevel); - } - - internal function startPlaying(url:String, - startedCallback:String = null, - finishedCallback:String = null, - failedCallback:String = null):void - { - recorder.stop(true); - player.start(url, new WamiListener(startedCallback, finishedCallback, failedCallback)); - } - - internal function stopPlaying():void - { - player.stop(); - } - - internal function getPlayingLevel():int - { - return player.level(); - } - - private function startListening(paddingMillis:uint = 200):void - { - recorder.listen(paddingMillis); - } - - private function stopListening():void - { - recorder.unlisten(); - } - - internal function startRecording(url:String, - startedCallback:String = null, - finishedCallback:String = null, - failedCallback:String = null):void - { - recorder.start(url, new WamiListener(startedCallback, finishedCallback, failedCallback)); - } - - internal function stopRecording():void - { - recorder.stop(); - } - - internal function getRecordingLevel():int - { - return recorder.level(); - } - } -} - diff --git a/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/client/WamiListener.as b/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/client/WamiListener.as deleted file mode 100644 index f472fb0473..0000000000 --- a/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/client/WamiListener.as +++ /dev/null @@ -1,61 +0,0 @@ -/* -* Copyright (c) 2011 -* Spoken Language Systems Group -* MIT Computer Science and Artificial Intelligence Laboratory -* Massachusetts Institute of Technology -* -* Permission is hereby granted, free of charge, to any person -* obtaining a copy of this software and associated documentation -* files (the "Software"), to deal in the Software without -* restriction, including without limitation the rights to use, copy, -* modify, merge, publish, distribute, sublicense, and/or sell copies -* of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be -* included in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -*/ -package edu.mit.csail.wami.client -{ - import edu.mit.csail.wami.utils.External; - import edu.mit.csail.wami.utils.StateListener; - - /** - * Translates audio events into Javascript callbacks. - */ - public class WamiListener implements StateListener - { - private var startCallback:String, finishedCallback:String, failedCallback:String; - - function WamiListener(startCallback:String, finishedCallback:String, failedCallback:String) - { - this.startCallback = startCallback; - this.finishedCallback = finishedCallback; - this.failedCallback = failedCallback; - } - - public function started():void - { - External.call(startCallback); - } - - public function finished():void - { - External.call(finishedCallback); - } - - public function failed(error:Error):void - { - External.call(failedCallback, error.message); - } - } -} \ No newline at end of file diff --git a/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/client/WamiParams.as b/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/client/WamiParams.as deleted file mode 100644 index bacc3fe168..0000000000 --- a/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/client/WamiParams.as +++ /dev/null @@ -1,180 +0,0 @@ -/* -* Copyright (c) 2011 -* Spoken Language Systems Group -* MIT Computer Science and Artificial Intelligence Laboratory -* Massachusetts Institute of Technology -* -* Permission is hereby granted, free of charge, to any person -* obtaining a copy of this software and associated documentation -* files (the "Software"), to deal in the Software without -* restriction, including without limitation the rights to use, copy, -* modify, merge, publish, distribute, sublicense, and/or sell copies -* of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be -* included in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -*/ -package edu.mit.csail.wami.client -{ - import edu.mit.csail.wami.audio.AudioFormat; - import edu.mit.csail.wami.utils.External; - - import flash.media.Microphone; - import flash.utils.ByteArray; - import flash.utils.Endian; - - /** - * A class documents the possible parameters and sets a few defaults. - * The defaults are set up to stream to localhost. - */ - public class WamiParams - { - private var mic:Microphone; - - // Show the debug interface. - public var visible:Boolean = true; - - // Append this many milliseconds of audio before - // and after calls to startRecording/stopRecording. - public var paddingMillis:uint = 250; - - // Send the audio using multiple HTTP Posts. - public var stream:Boolean = false; - - // The URLs used in the debugging interface. - public var testRecordUrl:String = "https://wami-recorder.appspot.com/audio"; - public var testPlayUrl:String = "https://wami-recorder.appspot.com/audio"; - - // Callbacks for loading the client. - public var loadedCallback:String; - public var format:AudioFormat; - - public function WamiParams(params:Object):void - { - mic = Microphone.getMicrophone(); - - External.addCallback("setSettings", setSettings); - External.addCallback("getSettings", getSettings); - - if (params.stream != undefined) - { - stream = params.stream == "true"; - } - - if (params.visible != undefined) - { - visible = params.visible == "true"; - } - - if (params.console != undefined) { - External.debugToConsole = params.console == "true"; - } - - // Override to allow recording at 8000 and 16000 as well. - // Note that playback at these sample-rates will be sped up. - if (params.allrates != undefined) { - AudioFormat.allrates = params.allrates == "true"; - } - - loadedCallback = params.loadedCallback; - - var rate:uint = 22050; - if (params.rate != undefined) - { - rate = uint(params.rate); - } - format = new AudioFormat(rate, 1, 16, Endian.LITTLE_ENDIAN); - } - - public function getMicrophone():Microphone { - return mic; - } - - // Settings (including microphone security) are passed back here. - internal function getSettings():Object - { - var json:Object = { - "container" : (stream) ? "au" : "wav", - "encoding" : "pcm", - "signed" : true, - "sampleSize" : format.bits, - "bigEndian" : format.endian == Endian.BIG_ENDIAN, - "sampleRate" : format.rate, - "numChannels" : format.channels, - "interleaved" : true, - "microphone" : { - "granted" : (mic != null && !mic.muted) - } - }; - - return json; - } - - internal function setSettings(json:Object):void - { - if (json) - { - // For now the type also specifies streaming or not. - if (json.container == "au") - { - stream = true; - } - else if (json.container == "wav") - { - stream = false; - } - - if (json.encoding) - { - throw new Error("Encodings such as mu-law could be implemented."); - } - - if (json.signed) - { - throw new Error("Not implemented yet."); - } - - if (json.bigEndian) - { - throw new Error("Automatically determined."); - } - - if (json.numChannels) - { - format.channels = json.numChannels; - } - - if (json.sampleSize) - { - format.bits = json.sampleSize; - } - - if (json.interleaved) - { - throw new Error("Always true."); - } - - if (json.microphone) - { - throw new Error("Only the user can change the microphone security settings."); - } - - if (json.sampleRate) - { - format.rate = json.sampleRate; - } - - } - } - } -} \ No newline at end of file diff --git a/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/play/IPlayer.as b/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/play/IPlayer.as deleted file mode 100644 index 19975036c0..0000000000 --- a/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/play/IPlayer.as +++ /dev/null @@ -1,39 +0,0 @@ -/* -* Copyright (c) 2011 -* Spoken Language Systems Group -* MIT Computer Science and Artificial Intelligence Laboratory -* Massachusetts Institute of Technology -* -* Permission is hereby granted, free of charge, to any person -* obtaining a copy of this software and associated documentation -* files (the "Software"), to deal in the Software without -* restriction, including without limitation the rights to use, copy, -* modify, merge, publish, distribute, sublicense, and/or sell copies -* of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be -* included in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -*/ -package edu.mit.csail.wami.play -{ - import edu.mit.csail.wami.utils.StateListener; - - public interface IPlayer - { - function start(url:String, listener:StateListener):void; - function stop():void; - - // Audio level (between 0 and 100) - function level():int; - } -} \ No newline at end of file diff --git a/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/play/WamiPlayer.as b/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/play/WamiPlayer.as deleted file mode 100644 index 3ad3b57459..0000000000 --- a/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/play/WamiPlayer.as +++ /dev/null @@ -1,179 +0,0 @@ -/* -* Copyright (c) 2011 -* Spoken Language Systems Group -* MIT Computer Science and Artificial Intelligence Laboratory -* Massachusetts Institute of Technology -* -* Permission is hereby granted, free of charge, to any person -* obtaining a copy of this software and associated documentation -* files (the "Software"), to deal in the Software without -* restriction, including without limitation the rights to use, copy, -* modify, merge, publish, distribute, sublicense, and/or sell copies -* of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be -* included in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -*/ -package edu.mit.csail.wami.play -{ - import edu.mit.csail.wami.audio.AuContainer; - import edu.mit.csail.wami.audio.DecodePipe; - import edu.mit.csail.wami.audio.IAudioContainer; - import edu.mit.csail.wami.audio.WaveContainer; - import edu.mit.csail.wami.utils.BytePipe; - import edu.mit.csail.wami.utils.External; - import edu.mit.csail.wami.utils.Pipe; - import edu.mit.csail.wami.utils.StateListener; - - import flash.events.Event; - import flash.events.HTTPStatusEvent; - import flash.events.IOErrorEvent; - import flash.events.ProgressEvent; - import flash.events.SampleDataEvent; - import flash.events.SecurityErrorEvent; - import flash.media.Sound; - import flash.media.SoundChannel; - import flash.net.URLLoader; - import flash.net.URLLoaderDataFormat; - import flash.net.URLRequest; - import flash.net.URLRequestMethod; - import flash.utils.ByteArray; - - public class WamiPlayer implements IPlayer - { - private var currentChannel:SoundChannel = null; - private var currentAudio:ByteArray; - private var listener:StateListener; - - public function start(url:String, listener:StateListener):void - { - this.listener = listener; - var loader:URLLoader = new URLLoader(); - loader.dataFormat = URLLoaderDataFormat.BINARY; - - loader.addEventListener(Event.COMPLETE, completeHandler); - loader.addEventListener(Event.OPEN, openHandler); - loader.addEventListener(ProgressEvent.PROGRESS, progressHandler); - loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler); - loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler); - loader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler); - - var request:URLRequest = new URLRequest(url); - request.method = URLRequestMethod.GET; - - try { - loader.load(request); - } catch (error:Error) { - listener.failed(error); - } - - function completeHandler(event:Event):void { - listener.started(); - - loader.removeEventListener(Event.COMPLETE, completeHandler); - loader.removeEventListener(Event.OPEN, openHandler); - loader.removeEventListener(ProgressEvent.PROGRESS, progressHandler); - loader.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler); - loader.removeEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler); - loader.removeEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler) - - play(loader.data); - } - - function openHandler(event:Event):void { - External.debug("openHandler: " + event); - } - - function progressHandler(event:ProgressEvent):void { - //External.debug("progressHandler loaded:" + event.bytesLoaded + " total: " + event.bytesTotal); - } - - function securityErrorHandler(event:SecurityErrorEvent):void { - listener.failed(new Error("Security error while playing: " + event.errorID)); - } - - function httpStatusHandler(event:HTTPStatusEvent):void { - External.debug("httpStatusHandler: " + event); - } - - function ioErrorHandler(event:IOErrorEvent):void { - listener.failed(new Error("IO error while playing: " + event.errorID)); - } - } - - public function stop():void - { - if (currentChannel != null) - { - External.debug("Stop playing."); - currentChannel.removeEventListener(Event.SOUND_COMPLETE, stop); - currentChannel.stop(); - External.debug("Listener finished."); - listener.finished(); - currentChannel = null; - } - } - - public function level():int - { - if (currentChannel != null) { - return 100 * ((currentChannel.leftPeak + currentChannel.rightPeak) / 2.0); - } - - return 0; - } - - protected function play(audio:ByteArray):void - { - stop(); // Make sure we're stopped - - var containers:Vector. = new Vector.(); - containers.push(new WaveContainer()); - containers.push(new AuContainer()); - - External.debug("Playing audio of " + audio.length + " bytes."); - var decoder:Pipe = new DecodePipe(containers); - var pipe:BytePipe = new BytePipe(); - decoder.setSink(pipe); - decoder.write(audio); - decoder.close(); - - currentAudio = pipe.getByteArray(); - External.debug("Playing audio with " + currentAudio.length/4 + " samples."); - - var sound:Sound = new Sound(); - sound.addEventListener(SampleDataEvent.SAMPLE_DATA, handleSampleEvent); - - currentChannel = sound.play(); - currentChannel.addEventListener(Event.SOUND_COMPLETE, function(event:Event):void { - sound.removeEventListener(SampleDataEvent.SAMPLE_DATA, handleSampleEvent); - stop(); - }); - } - - private function handleSampleEvent(event:SampleDataEvent):void - { - if (currentAudio == null) return; - - var MAX_SAMPLES_PER_EVENT:uint = 4000; - var count:uint = 0; - // External.debug("Audio " + currentAudio.bytesAvailable + " " + event.data.endian); - while (currentAudio.bytesAvailable && count < MAX_SAMPLES_PER_EVENT) - { - event.data.writeFloat(currentAudio.readFloat()); - event.data.writeFloat(currentAudio.readFloat()); - count += 1; - } - } - } -} \ No newline at end of file diff --git a/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/record/ChunkPipe.as b/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/record/ChunkPipe.as deleted file mode 100644 index ff9776be3f..0000000000 --- a/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/record/ChunkPipe.as +++ /dev/null @@ -1,5 +0,0 @@ -/* * Copyright (c) 2011 * Spoken Language Systems Group * MIT Computer Science and Artificial Intelligence Laboratory * Massachusetts Institute of Technology * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation * files (the "Software"), to deal in the Software without * restriction, including without limitation the rights to use, copy, * modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ package edu.mit.csail.wami.record { import edu.mit.csail.wami.utils.Pipe; - - import flash.utils.ByteArray; - - /** * Data can be written to this pipe in any increment, but only chunks of a * fixed size will be passed on to the sink. */ public class ChunkPipe extends Pipe { private var chunkSize:int; private var closing:Boolean; private var buffer:ByteArray; public function ChunkPipe(size:int) { this.chunkSize = size; buffer = new ByteArray(); } override public function write(data:ByteArray):void { while (true) { var available:int = data.bytesAvailable + buffer.bytesAvailable; if (available < chunkSize && !closing) break; // if we get here, there's enough data for another chunk var chunk:ByteArray = new ByteArray(); // Add as much as we can from the buffer to this chunk var bufferAvailable:int = Math.min(buffer.bytesAvailable, chunkSize); buffer.readBytes(chunk, chunk.length, bufferAvailable); // Add as much as we can from the data passed in to this chunk var chunkRemainder:int = Math.max(chunkSize - bufferAvailable, 0); var dataAvailable:int = Math.min(data.bytesAvailable, chunkRemainder); data.readBytes(chunk, chunk.length, dataAvailable); // Write the chunk out chunk.position = 0; if (chunk.length > 0) super.write(chunk); if (closing) break; } updateBuffer(data); } private function updateBuffer(data:ByteArray):void { if (buffer.bytesAvailable == 0) { // The buffer hits 0 bytes available whenever // there was enough data to create a chunk... // still should clear out the junk we've written. buffer.clear(); } data.readBytes(buffer, buffer.length, data.bytesAvailable); buffer.position = 0; } override public function close():void { closing = true; write(new ByteArray()); super.close(); } } } \ No newline at end of file diff --git a/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/record/IRecorder.as b/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/record/IRecorder.as deleted file mode 100644 index d5e6e19085..0000000000 --- a/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/record/IRecorder.as +++ /dev/null @@ -1,49 +0,0 @@ -/* -* Copyright (c) 2011 -* Spoken Language Systems Group -* MIT Computer Science and Artificial Intelligence Laboratory -* Massachusetts Institute of Technology -* -* Permission is hereby granted, free of charge, to any person -* obtaining a copy of this software and associated documentation -* files (the "Software"), to deal in the Software without -* restriction, including without limitation the rights to use, copy, -* modify, merge, publish, distribute, sublicense, and/or sell copies -* of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be -* included in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -*/ -package edu.mit.csail.wami.record -{ - import edu.mit.csail.wami.utils.StateListener; - - public interface IRecorder - { - // Start and stop recording. Calling start while recording - // or calling stop when not recording should have no effect. - function start(url:String, listener:StateListener):void; - function stop(force:Boolean = false):void; - - // It can be helpful to buffer a certain amount of audio to - // prepend (and append) to the audio collected between start - // and stop. This means, Flash needs to constantly listen. - // There are other times when it's obvious no recording will - // be done, and so listening is unnecesary. - function listen(paddingMillis:uint):void; - function unlisten():void; - - // Audio level (between 0 and 100) - function level():int; - } -} \ No newline at end of file diff --git a/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/record/MultiPost.as b/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/record/MultiPost.as deleted file mode 100644 index 157cbe8ac6..0000000000 --- a/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/record/MultiPost.as +++ /dev/null @@ -1,111 +0,0 @@ -/* -* Copyright (c) 2011 -* Spoken Language Systems Group -* MIT Computer Science and Artificial Intelligence Laboratory -* Massachusetts Institute of Technology -* -* Permission is hereby granted, free of charge, to any person -* obtaining a copy of this software and associated documentation -* files (the "Software"), to deal in the Software without -* restriction, including without limitation the rights to use, copy, -* modify, merge, publish, distribute, sublicense, and/or sell copies -* of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be -* included in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -*/ -package edu.mit.csail.wami.record -{ - import edu.mit.csail.wami.utils.External; - import edu.mit.csail.wami.utils.Pipe; - import edu.mit.csail.wami.utils.StateListener; - - import flash.utils.ByteArray; - - public class MultiPost extends Pipe implements StateListener - { - private var url:String; - private var contentType:String = null; - private var partIndex:int = 0; - private var timeoutMillis:int; - private var totalBytes:int = 0; - private var totalPostsMade:int = 0; - private var totalPostsDone:int = 0; - private var error:Error = null; - private var listener:StateListener; - - /** - * Does of POST of the data passed in to every call to "write" - */ - public function MultiPost(url:String, type:String, timeoutMillis:int, listener:StateListener) - { - this.url = url; - this.contentType = type; - this.timeoutMillis = timeoutMillis; - this.listener = listener; - } - - override public function write(bytes:ByteArray):void - { - if (getError() != null) { - throw getError(); - } - - var type:String = contentType.replace("%s", partIndex++); - var post:Pipe = new SinglePost(url, type, timeoutMillis, this); - post.write(bytes); - post.close(); - totalBytes += bytes.length; - totalPostsMade++; - } - - // A final POST containing a -1 signifies the end of the MultiPost stream. - override public function close():void - { - External.debug("Total multi-posted bytes: " + totalBytes); - var arr:ByteArray = new ByteArray(); - arr.writeInt(-1); - arr.position = 0; - write(arr); - super.close(); - } - - public function started():void - { - // nothing to do - } - - public function finished():void - { - totalPostsDone++; - checkFinished(); - } - - public function failed(error:Error):void - { - this.error = error; - } - - public function getError():Error - { - return error; - } - - private function checkFinished():void - { - if (totalPostsDone == totalPostsMade && super.isClosed()) { - listener.finished(); - } - } - } -} \ No newline at end of file diff --git a/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/record/SinglePost.as b/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/record/SinglePost.as deleted file mode 100644 index 18cf4d1419..0000000000 --- a/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/record/SinglePost.as +++ /dev/null @@ -1,159 +0,0 @@ -/* -* Copyright (c) 2011 -* Spoken Language Systems Group -* MIT Computer Science and Artificial Intelligence Laboratory -* Massachusetts Institute of Technology -* -* Permission is hereby granted, free of charge, to any person -* obtaining a copy of this software and associated documentation -* files (the "Software"), to deal in the Software without -* restriction, including without limitation the rights to use, copy, -* modify, merge, publish, distribute, sublicense, and/or sell copies -* of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be -* included in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -*/ -package edu.mit.csail.wami.record -{ - import edu.mit.csail.wami.utils.External; - import edu.mit.csail.wami.utils.Pipe; - import edu.mit.csail.wami.utils.StateListener; - - import flash.events.Event; - import flash.events.HTTPStatusEvent; - import flash.events.IOErrorEvent; - import flash.events.ProgressEvent; - import flash.events.SecurityErrorEvent; - import flash.net.URLLoader; - import flash.net.URLRequest; - import flash.net.URLRequestMethod; - import flash.utils.ByteArray; - import flash.utils.setInterval; - - /** - * Write data and POST on close. - */ - public class SinglePost extends Pipe - { - private var url:String; - private var contentType:String = null; - private var listener:StateListener; - - private var finished:Boolean = false; - private var buffer:ByteArray = new ByteArray(); - private var timeoutMillis:int; - - public function SinglePost(url:String, type:String, timeoutMillis:int, listener:StateListener) - { - this.url = url; - this.contentType = type; - this.listener = listener; - this.timeoutMillis = timeoutMillis; - } - - override public function write(bytes:ByteArray):void - { - bytes.readBytes(buffer, buffer.length, bytes.bytesAvailable); - } - - override public function close():void - { - buffer.position = 0; - External.debug("POST " + buffer.length + " bytes of type " + contentType); - buffer.position = 0; - var loader:URLLoader = new URLLoader(); - - loader.addEventListener(Event.COMPLETE, completeHandler); - loader.addEventListener(Event.OPEN, openHandler); - loader.addEventListener(ProgressEvent.PROGRESS, progressHandler); - loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler); - loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler); - loader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler); - - var request:URLRequest = new URLRequest(url); - request.method = URLRequestMethod.POST; - request.contentType = contentType; - request.data = buffer; - if (buffer.bytesAvailable == 0) { - External.debug("Note that flash does a GET request if bytes.length == 0"); - } - - try { - loader.load(request); - } catch (error:Error) { - if (listener) - { - listener.failed(error); - } - } - - super.close(); - } - - private function completeHandler(event:Event):void { - External.debug("POST: completeHandler"); - var loader:URLLoader = URLLoader(event.target); - loader.removeEventListener(Event.COMPLETE, completeHandler); - loader.removeEventListener(Event.OPEN, openHandler); - loader.removeEventListener(ProgressEvent.PROGRESS, progressHandler); - loader.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler); - loader.removeEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler); - loader.removeEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler); - listener.finished(); - finished = true; - } - - private function openHandler(event:Event):void { - External.debug("POST openHandler: " + event); - setInterval(checkFinished, timeoutMillis); - } - - private function checkFinished():void { - if (!finished && listener) { - listener.failed(new Error("POST is taking too long.")); - } - finished = true; - } - - private function progressHandler(event:ProgressEvent):void { - External.debug("POST progressHandler loaded:" + event.bytesLoaded + " total: " + event.bytesTotal); - } - - private function securityErrorHandler(event:SecurityErrorEvent):void { - if (!finished && listener) - { - listener.failed(new Error("Record security error: " + event.errorID)); - } - finished = true; - } - - private function httpStatusHandler(event:HTTPStatusEvent):void { - // Apparently the event.status can be zero in some environments where nothing is wrong: - // http://johncblandii.com/2008/04/flex-3-firefox-beta-3-returns-0-for-http-status-codes.html - if (!finished && listener && event.status != 200 && event.status != 0) - { - listener.failed(new Error("HTTP status error: " + event.status)); - } - finished = true; - } - - private function ioErrorHandler(event:IOErrorEvent):void { - if (!finished && listener) - { - listener.failed(new Error("Record IO error: " + event.errorID)); - } - finished = true; - } - } -} \ No newline at end of file diff --git a/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/record/WamiRecorder.as b/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/record/WamiRecorder.as deleted file mode 100644 index 55e6206dcd..0000000000 --- a/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/record/WamiRecorder.as +++ /dev/null @@ -1,269 +0,0 @@ -/* -* Copyright (c) 2011 -* Spoken Language Systems Group -* MIT Computer Science and Artificial Intelligence Laboratory -* Massachusetts Institute of Technology -* -* Permission is hereby granted, free of charge, to any person -* obtaining a copy of this software and associated documentation -* files (the "Software"), to deal in the Software without -* restriction, including without limitation the rights to use, copy, -* modify, merge, publish, distribute, sublicense, and/or sell copies -* of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be -* included in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -*/ -package edu.mit.csail.wami.record -{ - import edu.mit.csail.wami.audio.AuContainer; - import edu.mit.csail.wami.audio.AudioFormat; - import edu.mit.csail.wami.audio.EncodePipe; - import edu.mit.csail.wami.audio.IAudioContainer; - import edu.mit.csail.wami.audio.WaveContainer; - import edu.mit.csail.wami.client.WamiParams; - import edu.mit.csail.wami.utils.BytePipe; - import edu.mit.csail.wami.utils.External; - import edu.mit.csail.wami.utils.Pipe; - import edu.mit.csail.wami.utils.StateListener; - - import flash.events.SampleDataEvent; - import flash.events.StatusEvent; - import flash.media.Microphone; - import flash.media.SoundCodec; - import flash.utils.Endian; - import flash.utils.clearInterval; - import flash.utils.setInterval; - - public class WamiRecorder implements IRecorder - { - private static var CHUNK_DURATION_MILLIS:Number = 200; - - private var mic:Microphone = null; - private var params:WamiParams; - private var audioPipe:Pipe; - - // For adding some audio padding to start and stop. - private var circularBuffer:BytePipe; - private var stopInterval:uint; - private var paddingMillis:uint = 0; // initially 0, but listen changes it. - private var listening:Boolean = false; - - // To determine if the amount of audio recorded matches up with - // the length of time we've recorded (i.e. not dropping any frames) - private var handled:uint; - private var startTime:Date; - private var stopTime:Date; - private var listener:StateListener; - - public function WamiRecorder(mic:Microphone, params:WamiParams) - { - this.params = params; - this.circularBuffer = new BytePipe(getPaddingBufferSize()); - this.mic = mic; - mic.addEventListener(StatusEvent.STATUS, onMicStatus); - - if (getChunkSize() <= 0) - { - throw new Error("Desired duration is too small, even for streaming chunks: " + getChunkSize()); - } - } - - /** - * The WAMI recorder can listen constantly, keeping a buffer of the last - * few milliseconds of audio. Often people start talking before they click the - * button, so we prepend paddingMillis milliseconds to the audio. - */ - public function listen(paddingMillis:uint):void { - if (!listening) { - this.paddingMillis = paddingMillis; - mic.rate = AudioFormat.toRoundedRate(params.format.rate); - mic.codec = SoundCodec.NELLYMOSER; // Just to clarify 5, 8, 11, 16, 22 and 44 kHz - mic.setSilenceLevel(0, 10000); - mic.addEventListener(SampleDataEvent.SAMPLE_DATA, sampleHandler); - External.debug("Listening..."); - listening = true; - } - } - - public function unlisten():void { - if (listening) { - mic.removeEventListener(SampleDataEvent.SAMPLE_DATA, sampleHandler); - listening = false; - if (paddingMillis > 0) { - circularBuffer = new BytePipe(getPaddingBufferSize()); - } - External.debug("Unlistening."); - } - } - - protected function onMicStatus(event:StatusEvent):void - { - External.debug("status: " + event.code); - if (event.code == "Microphone.Unmuted") - { - listen(this.paddingMillis); - } else if (event.code == "Microphone.Muted") { - unlisten(); - } - } - - public function start(url:String, listener:StateListener):void - { - // Forces security if mic is still muted in debugging mode. - listen(this.paddingMillis); - - // Flash might be able to decide on a different sample rate - // than the one you suggest depending on your audio card... - params.format.rate = AudioFormat.fromRoundedRate(mic.rate); - External.debug("Recording at rate: " + params.format.rate); - - stop(true); - audioPipe = createAudioPipe(url, listener); - - if (paddingMillis > 0) { - // Prepend a small amount of audio we've already recorded. - circularBuffer.close(); - audioPipe.write(circularBuffer.getByteArray()); - circularBuffer = new BytePipe(getPaddingBufferSize()); - } - - listener.started(); - - handled = 0; - startTime = new Date(); - } - - public function createAudioPipe(url:String, listener:StateListener):Pipe - { - this.listener = listener; - - var post:Pipe; - var container:IAudioContainer; - if (params.stream) - { - // The chunk parameter is something I made up. It would need - // to be handled on the server-side to piece all the chunks together. - post = new MultiPost(url, "audio/basic; chunk=%s", 3*1000, listener); - params.format.endian = Endian.BIG_ENDIAN; - container = new AuContainer(); - } - else - { - post = new SinglePost(url, "audio/x-wav", 30*1000, listener); - container = new WaveContainer(); - } - - // Setup the audio pipes. A transcoding pipe converts floats - // to shorts and passes them on to a chunking pipe, which spits - // out chunks to a pipe that possibly adds a WAVE header - // before passing the chunks on to a pipe that does HTTP posts. - var pipe:Pipe = new EncodePipe(params.format, container); - pipe.setSink(new ChunkPipe(getChunkSize())) - .setSink(post); - - return pipe; - } - - internal function sampleHandler(evt:SampleDataEvent):void - { - evt.data.position = 0; - try - { - if (audioPipe) - { - audioPipe.write(evt.data); - handled += evt.data.length / 4; - } - else if (paddingMillis > 0) - { - circularBuffer.write(evt.data); - } - } - catch (error:Error) - { - audioPipe = null; - stop(true); - listener.failed(error); - } - } - - public function stop(force:Boolean = false):void - { - clearInterval(stopInterval); - - if (force) - { - reallyStop(); - } - else - { - stopInterval = setInterval(function():void { - clearInterval(stopInterval); - reallyStop(); - }, paddingMillis); - } - } - - public function level():int - { - if (!audioPipe) return 0; - return mic.activityLevel; - } - - private function reallyStop():void - { - if (!audioPipe) return; - - try { - audioPipe.close(); - } catch(error:Error) { - listener.failed(error); - } - - audioPipe = null; - validateAudioLength(); - - if (this.paddingMillis == 0) { - // No need if we're not padding the audio - unlisten(); - } - } - - private function validateAudioLength():void - { - stopTime = new Date(); - var seconds:Number = ((stopTime.time - startTime.time + paddingMillis) / 1000.0); - var expectedSamples:uint = uint(seconds*params.format.rate); - External.debug("Expected Samples: " + expectedSamples + " Actual Samples: " + handled); - startTime = null; - stopTime = null; - } - - private function getBytesPerSecond():uint - { - return params.format.channels * (params.format.bits/8) * params.format.rate; - } - - private function getChunkSize():uint - { - return params.stream ? getBytesPerSecond() * CHUNK_DURATION_MILLIS / 1000.0 : int.MAX_VALUE; - } - - private function getPaddingBufferSize():uint - { - return uint(getBytesPerSecond()*params.paddingMillis/1000.0); - } - - } -} \ No newline at end of file diff --git a/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/utils/BytePipe.as b/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/utils/BytePipe.as deleted file mode 100644 index 22861410c2..0000000000 --- a/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/utils/BytePipe.as +++ /dev/null @@ -1,93 +0,0 @@ -/* -* Copyright (c) 2011 -* Spoken Language Systems Group -* MIT Computer Science and Artificial Intelligence Laboratory -* Massachusetts Institute of Technology -* -* Permission is hereby granted, free of charge, to any person -* obtaining a copy of this software and associated documentation -* files (the "Software"), to deal in the Software without -* restriction, including without limitation the rights to use, copy, -* modify, merge, publish, distribute, sublicense, and/or sell copies -* of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be -* included in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -*/ -package edu.mit.csail.wami.utils -{ - import flash.utils.ByteArray; - - /** - * Accumulates the written bytes into an array. If a max number of bytes - * is specified this will act as a circular buffer. - */ - public class BytePipe extends Pipe - { - private var buffer:ByteArray = new ByteArray(); - private var done:Boolean = false; - private var maxBytes:uint; - private var start:uint = 0; - - function BytePipe(maxBytes:uint = uint.MAX_VALUE):void - { - this.maxBytes = maxBytes; - } - - override public function write(bytes:ByteArray):void - { - if (maxBytes <= 0) return; // no room! - - var available:uint = Math.min(maxBytes - buffer.length, bytes.bytesAvailable); - if (available > 0) - { - bytes.readBytes(buffer, buffer.length, available); - } - - while (bytes.bytesAvailable) - { - // Read bytes into the circular buffer. - available = Math.min(buffer.length - start, bytes.bytesAvailable); - bytes.readBytes(buffer, start, available); - start = (start + available) % maxBytes; - } - - buffer.position = 0; - } - - override public function close():void - { - super.close(); - done = true; - } - - public function getByteArray():ByteArray - { - if (!done) - { - throw new Error("BytePipe should be done before accessing byte array."); - } - - var array:ByteArray = new ByteArray(); - buffer.position = start; - buffer.readBytes(array); - buffer.position = 0; - if (start > 0) - { - buffer.readBytes(array, array.length, start); - } - array.position = 0; - return array; - } - } -} \ No newline at end of file diff --git a/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/utils/External.as b/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/utils/External.as deleted file mode 100644 index 85695d8030..0000000000 --- a/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/utils/External.as +++ /dev/null @@ -1,144 +0,0 @@ -/* -* Copyright (c) 2011 -* Spoken Language Systems Group -* MIT Computer Science and Artificial Intelligence Laboratory -* Massachusetts Institute of Technology -* -* Permission is hereby granted, free of charge, to any person -* obtaining a copy of this software and associated documentation -* files (the "Software"), to deal in the Software without -* restriction, including without limitation the rights to use, copy, -* modify, merge, publish, distribute, sublicense, and/or sell copies -* of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be -* included in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -*/ -package edu.mit.csail.wami.utils -{ - import flash.external.ExternalInterface; - import flash.utils.ByteArray; - - /** - * Make external calls only if available. - */ - public class External - { - public static var debugToConsole:Boolean = false; - - public static function call(functionName:String, ... arguments):void - { - if (ExternalInterface.available && functionName) - { - try - { - trace("External.call: " + functionName + "(" + arguments + ")"); - ExternalInterface.call(functionName, arguments); - } - catch (e:Error) - { - trace("Error calling external function: " + e.message); - } - } - else - { - trace("No ExternalInterface - External.call: " + functionName + "(" + arguments + ")"); - } - } - - public static function addCallback(functionName:String, closure:Function):void - { - if (ExternalInterface.available && functionName) - { - try - { - External.debug("External.addCallback: " + functionName); - ExternalInterface.addCallback(functionName, closure); - } - catch (e:Error) - { - External.debug("Error calling external function: " + e.message); - } - } - else - { - External.debug("No ExternalInterface - External.addCallback: " + functionName); - } - } - - public static function debug(msg:String):void - { - if (debugToConsole) { - ExternalInterface.call("console.log", "FLASH: " + msg); - } - else - { - trace(msg); - } - } - - public static function debugBytes(bytes:ByteArray):void - { - debug(bytesToHex(bytes)); - } - - public static function bytesToHex(bytes:ByteArray):String - { - var position:int = bytes.position; - var count:int = 0; - var str:String = "<"; - while (bytes.bytesAvailable) - { - if (count%4 == 0) - { - str += " 0x"; - } - var byte:uint = bytes.readUnsignedByte(); - var nib1:uint = byte/16; - var nib2:uint = byte%16; - str += getHex(nib1) + getHex(nib2); - count++; - } - str += " >"; - - // Reset position - bytes.position = position; - return str; - } - - private static function getHex(nibble:uint):String - { - switch(nibble) - { - case 0: return '0'; - case 1: return '1'; - case 2: return '2'; - case 3: return '3'; - case 4: return '4'; - case 5: return '5'; - case 6: return '6'; - case 7: return '7'; - case 8: return '8'; - case 9: return '9'; - case 10: return 'a'; - case 11: return 'b'; - case 12: return 'c'; - case 13: return 'd'; - case 14: return 'e'; - case 15: return 'f'; - } - - return "ERROR(" + nibble + ")"; - } - } -} \ No newline at end of file diff --git a/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/utils/Pipe.as b/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/utils/Pipe.as deleted file mode 100644 index d46ad0d41a..0000000000 --- a/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/utils/Pipe.as +++ /dev/null @@ -1,3 +0,0 @@ -/* * Copyright (c) 2011 * Spoken Language Systems Group * MIT Computer Science and Artificial Intelligence Laboratory * Massachusetts Institute of Technology * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation * files (the "Software"), to deal in the Software without * restriction, including without limitation the rights to use, copy, * modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ package edu.mit.csail.wami.utils { import flash.utils.ByteArray; - /** * A pipe is a base class that can be written to, and will * in turn write to a sink. Overriding "write" and "close" * allows a subclass to perform operations on the incoming * bytes before passing them on. */ - public class Pipe { private var sink:Pipe = null; private var closed:Boolean = false; public function write(bytes:ByteArray):void { if (closed) { throw new Error("Writing to closed pipe"); } if (sink) { sink.write(bytes); } } public function setSink(pipe:Pipe):Pipe { sink = pipe; return sink; } public function close():void { if (closed) { throw new Error("Pipe already closed"); } if (sink) { sink.close(); } closed = true; } public function isClosed():Boolean { return closed; } } } \ No newline at end of file diff --git a/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/utils/StateListener.as b/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/utils/StateListener.as deleted file mode 100644 index dbd871c090..0000000000 --- a/main/inc/lib/wami-recorder/src/edu/mit/csail/wami/utils/StateListener.as +++ /dev/null @@ -1,35 +0,0 @@ -/* -* Copyright (c) 2011 -* Spoken Language Systems Group -* MIT Computer Science and Artificial Intelligence Laboratory -* Massachusetts Institute of Technology -* -* Permission is hereby granted, free of charge, to any person -* obtaining a copy of this software and associated documentation -* files (the "Software"), to deal in the Software without -* restriction, including without limitation the rights to use, copy, -* modify, merge, publish, distribute, sublicense, and/or sell copies -* of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be -* included in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -* SOFTWARE. -*/ -package edu.mit.csail.wami.utils -{ - public interface StateListener - { - function started():void; - function finished():void; - function failed(error:Error):void; - } -} \ No newline at end of file diff --git a/main/install/db_main.sql b/main/install/db_main.sql index 8149b92792..962caa4346 100644 --- a/main/install/db_main.sql +++ b/main/install/db_main.sql @@ -864,7 +864,8 @@ VALUES ('login_is_email', NULL, 'radio', 'Platform', 'false', 'LoginIsEmailTitle', 'LoginIsEmailComment', NULL, NULL, 0), ('courses_default_creation_visibility', NULL, 'radio', 'Course', '2', 'CoursesDefaultCreationVisibilityTitle', 'CoursesDefaultCreationVisibilityComment', NULL, NULL, 1), ('allow_browser_sniffer', NULL, 'radio', 'Tuning', 'false', 'AllowBrowserSnifferTitle', 'AllowBrowserSnifferComment', NULL, NULL, 0), -('chamilo_database_version',NULL,'textfield',NULL, '1.9.0.17053','DokeosDatabaseVersion','', NULL, NULL, 0); +('enable_wami_record',NULL,'radio','Tools','false','EnableWamiRecordTitle','EnableWamiRecordComment',NULL,NULL, 0), +('chamilo_database_version',NULL,'textfield',NULL, '1.9.0.17054','DokeosDatabaseVersion','', NULL, NULL, 0); /* ('show_tabs', 'custom_tab_1', 'checkbox', 'Platform', 'true', 'ShowTabsTitle', 'ShowTabsComment', NULL, 'TabsCustom1', 1), @@ -1201,7 +1202,9 @@ VALUES ('courses_default_creation_visibility', '1', 'Private'), ('courses_default_creation_visibility', '0', 'CourseVisibilityClosed'), ('allow_browser_sniffer', 'true', 'Yes'), -('allow_browser_sniffer', 'false', 'No'); +('allow_browser_sniffer', 'false', 'No'), +('enable_wami_record', 'true', 'Yes'), +('enable_wami_record', 'false', 'No'); UNLOCK TABLES; /* diff --git a/main/install/migrate-db-1.8.8-1.9.0-pre.sql b/main/install/migrate-db-1.8.8-1.9.0-pre.sql index 4184c9a552..802f21b3ae 100755 --- a/main/install/migrate-db-1.8.8-1.9.0-pre.sql +++ b/main/install/migrate-db-1.8.8-1.9.0-pre.sql @@ -148,6 +148,11 @@ INSERT INTO settings_current (variable, subkey, type, category, selected_value, INSERT INTO settings_options (variable, value, display_text) VALUES ('allow_browser_sniffer', 'true', 'Yes'); INSERT INTO settings_options (variable, value, display_text) VALUES ('allow_browser_sniffer', 'false', 'No'); +INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('enable_wami_record', NULL, 'radio', 'Tools', 'false', 'EnableWamiRecordTitle', 'EnableWamiRecordComment', NULL, NULL, 0); +INSERT INTO settings_options (variable, value, display_text) VALUES ('enable_wami_record', 'true', 'Yes'); +INSERT INTO settings_options (variable, value, display_text) VALUES ('enable_wami_record', 'false', 'No'); + + -- Course ranking CREATE TABLE track_course_ranking (id int unsigned not null PRIMARY KEY AUTO_INCREMENT,c_id int unsigned not null, session_id int unsigned not null default 0, url_id int unsigned not null default 0, accesses int unsigned not null default 0, total_score int unsigned not null default 0, users int unsigned not null default 0, creation_date datetime not null);