Xinference 音频 piliqiu 收录于 Xinference2024-06-25 约 300 字 预计阅读 1 分钟 - 次阅读 警告 本文最后更新于 2024-06-25,文中内容可能已过时。 使用 Xinference 将音频转换为文本 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 <body> <input type="file" name="files" id="folderInput" multiple> <button onclick="uploadMp3()">上传</button> <script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2.0.5/FileSaver.min.js"></script> <script> async function uploadMp3() { //根据id获取元素 const inputElement = document.getElementById('folderInput'); const files = inputElement.files; var formData = new FormData(); formData.append('model', 'whisper-large-v3'); // 模型UID var txtName = '' //文件名字 if (files.length > 0) { // 使用FormData发送文件到服务器 for (let i = 0; i < files.length; i++) { formData.delete('file') formData.append('file', files[i]); var fileName = files[i].name // console.log(typeof fileName) fileName = fileName.substring(0, fileName.lastIndexOf(".")) //发送请求 await fetch('http://IP:端口/v1/audio/transcriptions', { method: 'POST', headers: { 'accept': '*/*', }, body: formData }).then(response => { if (!response.ok) { throw new Error('Network response was not ok'); } return response.json(); }).then(data => { var blob = new Blob([data.text], { type: 'text/plain' }); var link = document.createElement('a'); link.href = window.URL.createObjectURL(blob); // link.download = 'output.txt'; link.download = fileName + '.txt'; fileName = '' //使用过后记得清空 document.body.appendChild(link); link.click(); document.body.removeChild(link); }).catch(error => { alert("上传出错: " + error.message); }); } } } </script> </body>