多亏了 Cordova,我设法像录音机一样录制和播放我的声音。现在我想在我的声音上添加“Autotune”或“Vocoder”效果,我该怎么做?
PS:我在移动设备上工作。
这是录制和播放我的声音的脚本:
<script type="text/javascript" charset="utf-8" src="cordova-1.7.0rc1.js"></script>
<script type="text/javascript" src="jquery-1.7.1.js"></script>
<script type="text/javascript">
var deviceready = false;
var mediaVar = null;
var recordFileName = "recording.wav";
var status = null;
var isIOS = false;
function onBodyLoad()
{
document.addEventListener("deviceready", onDeviceReady, false);
deviceready = true;
}
$(document).ready(function(){
$("#stopBtn").hide();
$("#playBtn").hide();
//validation to check if device is ready is skipped
$("#recordBtn").click(function(){
record();
});
$("#playBtn").click(function(){
play();
});
$("#stopBtn").click(function(){
stop();
});
});
function record()
{
createMedia(function(){
status = "recording";
mediaVar.startRecord();
$("#recordBtn").hide();
$("#stopBtn").show();
$("#playBtn").hide();
},onStatusChange);
}
function createMedia(onMediaCreated, mediaStatusCallback){
if (mediaVar != null) {
onMediaCreated();
return;
}
if (typeof mediaStatusCallback == 'undefined')
mediaStatusCallback = null;
if (isIOS) {
//first create the file
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem){
fileSystem.root.getFile(recordFileName, {
create: true,
exclusive: false
}, function(fileEntry){
log("File " + recordFileName + " created at " + fileEntry.fullPath);
mediaVar = new Media(fileEntry.fullPath, function(){
log("Media created successfully");
}, onError, mediaStatusCallback); //of new Media
onMediaCreated();
}, onError); //of getFile
}, onError); //of requestFileSystem
} else //it's Android
{
mediaVar = new Media(recordFileName, function(){
log("Media created successfully");
}, onError, mediaStatusCallback);
onMediaCreated();
}
}
function stop()
{
if (mediaVar == null)
return;
if (status == 'recording')
{
mediaVar.stopRecord();
log("Recording stopped");
}
else if (status == 'playing')
{
mediaVar.stop();
log("Play stopped");
}
else
{
log("Nothing stopped");
}
$("#recordBtn").show();
$("#stopBtn").hide();
$("#playBtn").show();
status = 'stopped';
}
function play()
{
createMedia(function(){
status = "playing";
mediaVar.play();
$("#recordBtn").hide();
$("#stopBtn").show();
$("#playBtn").hide();
});
}
function onStatusChange()
{
if (arguments[0] == 4) //play stopped
{
$("#recordBtn").show();
$("#stopBtn").hide();
$("#playBtn").show();
}
}
function onSuccess()
{
//do nothing
}
function onError(err)
{
if (typeof err.message != 'undefined')
err = err.message;
alert("Error : " + err);
}
function log(message)
{
if (isIOS)
console.log(message);
else
console.info(message);
}
function onDeviceReady()
{
}
</script>