Wednesday, October 23, 2013

Record voice using microphone and upload to server using flash and PHP



Below is to get the flash from  Moodle LMS audio recording plugin and redesign PHP upload file.
Below is the snapshot of Moodle flash plugin interface:

1) Download moodle audio recording plugin:
https://moodle.org/plugins/pluginversions.php?plugin=assignment_onlineaudio
unzip and get onlineaudio folder,  copy assests/recorder.swf to your working directory.
2) Embed recorder.swf:
<embed type="application/x-shockwave-flash" src="recorder.swf" id="recorder" name="recorder" quality="high" wmode="transparent" flashvars="gateway=simpleupload.php" height="276" width="430">
3) create simpleupload.php to process the sound file produced by recorder.swf:
<?php
 $filename = preg_replace('/\s/', '', $_FILES['newfile']['name']);
$filetmpname = $_FILES['newfile']['tmp_name'];  

$ok = move_uploaded_file($filetmpname, "C:\\LMS\\uploads\\".$filename);
?>
In this example, the upload file will be put in C:\LMS\uploads\
4) To displayand play  the audio file (for example nn.mp3), I used the longtail_payer.swf from JW player:
<audio controls="controls">
 <source src="nn.mp3" />
 <!-- fallback -->
  <embed type="application/x-shockwave-flash"                                                        
    flashvars="audioUrl=nn.mp3"   
     src="longtail_player.swf"  
     width="650? height="0? quality="best"></embed>
</audio>`  

5)   For recorder using Flash Media server, refer to pRecorderTest. 115K Zip file in 
http://flash-communications.net/sourcecode/index.html

No comments:

Post a Comment