是的,文件不是很清楚。我昨天整個下午都在搞清楚。這是一個適用於我的本地機器的簡單實現。下面的文件都存儲在我的Apache文檔根目錄中的「/溫度/瓦米/測試」,所以網址爲「http://本地主機/溫度/瓦米/測試/」:
的index.html
記錄。 JS
save_file.php
Wami.swf
的index.html
<!-- index.html -->
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script src="https://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script></script>
<script src="recorder.js"></script>
</head>
<body>
<div id="recorder">
<button id="record">Record</button>
<button id="play">Play</button>
</div>
<div id="flash"></div>
</body>
<script>
// initialize Wami
Wami.setup({
id: 'flash' // where to put the flash object
});
// initialize some global vars
var recording = '';
var recordingUrl = '';
var playBackUrl = '';
// get button elements
var record = $('#record');
var play = $('#play');
// define functions
function startRecording() {
recording = 'temp.wav';
recordingUrl = 'http://localhost/temp/wami/test/save_file.php?filename=' + recording;
Wami.startRecording(recordingUrl);
// update button attributes
record
.html('Stop')
.unbind()
.click(function() {
stopRecording();
});
}
function stopRecording() {
Wami.stopRecording();
// get the recording for playback
playBackUrl = 'http://localhost/temp/wami/test/' + recording;
// update button attributes
record
.html('Record')
.unbind()
.click(function() {
startRecording();
});
}
function startPlaying() {
Wami.startPlaying(playBackUrl);
// update button attributes
play
.html('Stop')
.unbind()
.click(function() {
stopPlaying();
});
}
function stopPlaying() {
Wami.stopPlaying();
// update button attributes
play
.html('Play')
.unbind()
.click(function() {
startPlaying();
});
}
// add initial click functions
record.click(function() {
startRecording();
});
play.click(function() {
startPlaying();
});
</script>
</html>
save_file.php
<?php
/* save_file.php */
// get the filename
parse_str($_SERVER['QUERY_STRING'], $params);
$file = isset($params['filename']) ? $params['filename'] : 'temp.wav';
// save the recorded audio to that file
$content = file_get_contents('php://input');
$fh = fopen($file, 'w') or die("can't open file");
fwrite($fh, $content);
fclose($fh);
應該這樣做。不幸的是,似乎沒有辦法暫停然後恢復錄製。每次開始錄製時,它都會覆蓋以前的音頻。似乎也沒有辦法檢索關於音頻文件的信息(例如長度,大小)。請參閱Wami錄音機文件(recorder.js)以獲取錄音機功能的完整列表。
非常感謝你! – 2012-03-17 02:31:57
我正在拋出答案,但我沒有得到錄音功能 – ronan 2013-05-27 07:49:54
謝謝,像一個魅力工作!確保你將目錄保存爲可寫的文件夾:-) – 2013-07-13 10:46:52