gpt4 book ai didi

javascript - 如何使用 Phonegap 将音频文件转换为 iOS 上的 Base64 字符串?

转载 作者:行者123 更新时间:2023-11-28 07:55:43 26 4
gpt4 key购买 nike

此时我的应用程序非常简单。它记录一个音频文件。我想使用 readAsDataURL() 将音频文件转换为 base64 字符串
在phonegap api中。下面是我的代码。正如你所看到的,我正在关注 documentation用于获取下面的 base64 字符串。在下面的代码中,我尝试获取 base64 字符串并将其存储在变量中,然后使用该变量暂时在警报框中显示该字符串。截至目前,我只得到“data:audio/wav;base64”,我已经在这个问题上坚持了 4 周了。我真的很感激一些帮助。

 function gotFS(fileSystem) {
fileSystem.root.getFile("myaudio.wav", {create: true, exclusive: false}, gotFileEntry, fail);
}

function gotFileEntry(fileEntry) {
fileEntry.file(gotFile, fail);

}

function gotFile(file){
readDataUrl(file);

}

function readDataUrl(file) {
var reader = new FileReader();
reader.onloadend = function(evt) {
console.log("read success");
console.log(evt.target.result);
var thed = evt.target.result;
alert(thed); //trying to display the base64 string in an alert box
};
reader.readAsDataURL(file);
}

最佳答案

document.addEventListener("deviceready", init, false);
function init() {


//This alias is a read-only pointer to the app itself
window.resolveLocalFileSystemURL(cordova.file.applicationDirectory + "www/button-1.mp3", gotFile, fail);

// var src = "/android_asset/www/sounds/button-1.mp3";

}

function fail(e) {
// console.log("FileSystem Error");
// console.dir(e);
}

function gotFile(fileEntry) {

fileEntry.file(function(file) {
var reader = new FileReader();

reader.onloadend = function(e) {
console.log("Text is: "+this.result);

};

// reader.readAsText(file);
// reader.readAsArrayBuffer(file);
// reader.readAsBinaryString(file);
reader.readAsDataURL(file);
});

关于javascript - 如何使用 Phonegap 将音频文件转换为 iOS 上的 Base64 字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26112627/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com