【原创文章】,转载请注明作者博客:www.92ez.com或博客园地址
作者:KBdancer
前段时间由于项目需要,客户需求中有一条是要实现WEB端的录音功能,起初想到的是HTML5实现,经过几轮百度之后无果。
PS:谷歌时不时被墙,非必要时请不要使用百度搜索。
谷歌几番后发现一个实现录音的flash+js的插件,之前一直纠结的难题终 于解决。这款插件可以高度定制,自带众多与js交互的接口,(本人对action script实在是不怎么了解)能够轻松的使用js来控制录音的开始与停止和回放。对此款插件熟悉之后偶然在github上发现此插件的作者公开的API 文档,写的很详细。
话不多说,奉上API文档,虽然是英文的,但是应该不会影响阅读,关键的几个 方法我都已经用中文注释了(大概的意思翻译了一下,如有不对请告诉我)。先暂时把API文档发出,后面有时间的时候整理下DEMO也上传一下,希望能够帮 助需要的猿们(因为之前找了好久没找到好的解决方案,费了好多时间,猿们找资料都很辛苦)。
有图有真相:
Use flash to record audio data from a microphone. Converts the audio data to a WAV file. Uploads the WAV file to the server. The WAV file is POSTed as a multpart form-data request. Additional fields can be added to the request, such as authenticity_token, (response) formart, etc... The flash recorder creates serveral external interfaces. This allows the recorder to be controlled through javascript. Only the save button must be clicked inside the flash application, see Upload and download require user interaction for more information.
The event_handler is a javascript function that is called from the flash application. The first argument to the event_handler is always the name of the event as a string. The other arguments may vary depending on the event.
event_handler: javascript function called from the flash application
upload_image: image used as the save button
font_color: font color for the save text, default #0000EE
font_size: font size for the save text, default 12
save_text: text used for the save link, default Save
background_color: background color of the flash app, only used when using a save link
if upload_image failes recorder will use a save link instead
ready: recorder is ready for use
no_microphone_found: no microphone was found when trying to record
microphone_user_request: user needs to allow the recorder to access the microphone
microphone_connected: user allowed access to the microphone
microphone_not_connected: user denied access to the microphone, at this point the recorder CAN NOT be used until the user reloads the page
recording: recording audio data from the microphone
recording_stopped: stopped recording audio data
playing: playing back the recorded audio data
playback_started: useful for synchronizing playback with animation(注:用于同步回放与动画)
stopped: stopped playing back the recorded audio data(注:停止播放录音 )
save_pressed: save button was pressed in the recorder, good place to update the form data in the recorder(注:按下保存按钮)
saving: upload is in progress(注:正在上传 )
saved: upload is complete(注:上传录音成功 )
save_failed: the recorder failed to upload the audio data(注:保存失败 )
save_progress: upload progress(注:上传进度)
record: tells the recorder to record audio data from the microphone
will also stop recording if currently recording
playBack: tells the recorder to playback the recorded audio(注:回放录音)
will stop playback if called before playback ends
stopPlayBack: tells the recorder to stop recording or playback(注:停止回放)
duration: returns the duration of the recording(注:返回录音持续时间 )
init: setup the recorder for saving recordings
(注:为保存录音做准备)
permit: show the permissions dialog for microphone access, make sure the flash application is large enough for the dialog box before calling this method. Must be at least 240x160.
(注:显示权限许可对话框 大小至少 240X160)
show: show the save button(注:显示保存按钮)
hide: hide the save button(注:隐藏保存按钮)
update: update the form data
configure: configure microphone settings
setUseEchoSuppression: use echo suppression (注:使用回声抑制)
setLoopBack: routes audio captured by a microphone to the local speakers (注:本地扬声器播放从麦克风捕获到的音频)
getMicrophone: returns the microphone object (注:返回麦克风对象)