capacitor-audio-engine
Version:
High-quality audio recording Capacitor plugin with native iOS & Android support. Features pause/resume, microphone management, real-time monitoring, audio trimming, and comprehensive mobile audio recording capabilities.
2 lines (1 loc) • 9.61 kB
JavaScript
;var e,o,r,t,n,s,i,a,p,d,c=require("@capacitor/core");function u(e){if(!e.startsWith("data:"))return{isCompressed:!1,data:e,mimeType:"audio/m4a"};const[o,r]=e.split(",",2);return o.includes("lzfse:")?{isCompressed:!0,algorithm:"lzfse",data:r,mimeType:o.split(";")[0].replace("data:","")}:{isCompressed:!1,data:r,mimeType:o.split(";")[0].replace("data:","")}}exports.AudioSampleRate=void 0,(e=exports.AudioSampleRate||(exports.AudioSampleRate={}))[e.VOICE_8K=8e3]="VOICE_8K",e[e.VOICE_16K=16e3]="VOICE_16K",e[e.STANDARD_22K=22050]="STANDARD_22K",e[e.CD_44K=44100]="CD_44K",e[e.HIGH_48K=48e3]="HIGH_48K",exports.AudioChannels=void 0,(o=exports.AudioChannels||(exports.AudioChannels={}))[o.MONO=1]="MONO",o[o.STEREO=2]="STEREO",exports.AudioBitrate=void 0,(r=exports.AudioBitrate||(exports.AudioBitrate={}))[r.VERY_LOW=16e3]="VERY_LOW",r[r.LOW=32e3]="LOW",r[r.MEDIUM=64e3]="MEDIUM",r[r.HIGH=128e3]="HIGH",r[r.VERY_HIGH=256e3]="VERY_HIGH",exports.AudioQuality=void 0,(t=exports.AudioQuality||(exports.AudioQuality={})).LOW="low",t.MEDIUM="medium",t.HIGH="high",exports.WaveformBarsCount=void 0,(n=exports.WaveformBarsCount||(exports.WaveformBarsCount={}))[n.BARS_16=16]="BARS_16",n[n.BARS_32=32]="BARS_32",n[n.BARS_64=64]="BARS_64",n[n.BARS_128=128]="BARS_128",n[n.BARS_256=256]="BARS_256",exports.WaveformDebounceTime=void 0,(s=exports.WaveformDebounceTime||(exports.WaveformDebounceTime={}))[s.REALTIME=.02]="REALTIME",s[s.VERY_FAST=.05]="VERY_FAST",s[s.FAST=.1]="FAST",s[s.MEDIUM=.25]="MEDIUM",s[s.SLOW=.5]="SLOW",s[s.VERY_SLOW=1]="VERY_SLOW",exports.SpeechThreshold=void 0,(i=exports.SpeechThreshold||(exports.SpeechThreshold={}))[i.VERY_SENSITIVE=.005]="VERY_SENSITIVE",i[i.SENSITIVE=.01]="SENSITIVE",i[i.NORMAL=.02]="NORMAL",i[i.MODERATE=.04]="MODERATE",i[i.LESS_SENSITIVE=.06]="LESS_SENSITIVE",i[i.NOT_SENSITIVE=.1]="NOT_SENSITIVE",exports.VADWindowSize=void 0,(a=exports.VADWindowSize||(exports.VADWindowSize={}))[a.MINIMAL=3]="MINIMAL",a[a.LOW=4]="LOW",a[a.NORMAL=5]="NORMAL",a[a.MEDIUM=8]="MEDIUM",a[a.HIGH=10]="HIGH",a[a.MAXIMUM=15]="MAXIMUM",exports.CalibrationDuration=void 0,(p=exports.CalibrationDuration||(exports.CalibrationDuration={}))[p.QUICK=500]="QUICK",p[p.NORMAL=1e3]="NORMAL",p[p.EXTENDED=2e3]="EXTENDED",p[p.LONG=3e3]="LONG",exports.GainFactor=void 0,(d=exports.GainFactor||(exports.GainFactor={}))[d.MINIMAL=5]="MINIMAL",d[d.LOW=10]="LOW",d[d.STANDARD=15]="STANDARD",d[d.MEDIUM=20]="MEDIUM",d[d.HIGH=30]="HIGH",d[d.MAXIMUM=50]="MAXIMUM";const l=c.registerPlugin("CapacitorAudioEngine",{web:()=>Promise.resolve().then(function(){return w}).then(e=>new e.CapacitorAudioEngineWeb)});class m extends c.WebPlugin{async echo(e){return console.log("ECHO",e),e}async checkPermission(){return console.warn("checkPermission is not supported on web platform. For web implementation, consider using navigator.permissions.query API directly."),{granted:!1}}async requestPermission(){return console.warn("requestPermission is not supported on web platform. For web implementation, consider using navigator.mediaDevices.getUserMedia API directly."),{granted:!1}}async startRecording(e){throw console.warn("startRecording is not supported on web platform. For web implementation, consider using MediaRecorder API directly."),new Error("startRecording is not supported on web platform")}async stopRecording(){throw console.warn("stopRecording is not supported on web platform. For web implementation, consider using MediaRecorder API directly."),new Error("stopRecording is not supported on web platform")}async pauseRecording(){throw console.warn("pauseRecording is not supported on web platform. For web implementation, consider using MediaRecorder API directly."),new Error("pauseRecording is not supported on web platform")}async resumeRecording(){throw console.warn("resumeRecording is not supported on web platform. For web implementation, consider using MediaRecorder API directly."),new Error("resumeRecording is not supported on web platform")}async resetRecording(){throw console.warn("resetRecording is not supported on web platform. No recording buffers to reset."),new Error("resetRecording is not supported on web platform")}async getDuration(){return console.warn("getDuration is not supported on web platform. For web implementation, consider using MediaRecorder API directly."),{duration:0}}async getStatus(){return console.warn("getStatus is not supported on web platform. For web implementation, consider using MediaRecorder API directly."),{status:"idle",isRecording:!1,duration:0}}async trimAudio({uri:e,start:o,end:r}){throw console.warn(`trimAudio is not supported on web platform. Attempted to trim file: ${e} from ${o}s to ${r}s. For web implementation, consider using Web Audio API directly.`),new Error("trimAudio is not supported on web platform")}async addListener(e,o){console.warn(`${e} event is not supported on web platform. Callback will not be invoked. For web implementation, consider using MediaRecorder events directly.`);return{remove:()=>Promise.resolve()}}async isMicrophoneBusy(){throw console.warn("isMicrophoneBusy is not supported on web platform."),new Error("isMicrophoneBusy is not supported on web platform")}async getAvailableMicrophones(){throw console.warn("getAvailableMicrophones is not supported on web platform."),new Error("getAvailableMicrophones is not supported on web platform")}async switchMicrophone(e){throw console.warn(`switchMicrophone is not supported on web platform. Attempted to switch to microphone ID: ${e.microphoneId}`),new Error("switchMicrophone is not supported on web platform")}async removeAllListeners(){console.warn("removeAllListeners is not supported on web platform.")}async configureWaveform(){console.warn("configureWaveform is not supported on web platform. Waveform data is not available for web recordings. Consider using MediaRecorder events and manual amplitude analysis.");return{success:!1,configuration:{numberOfBars:128,debounceTimeMs:50,speechDetection:{enabled:!1,threshold:.02,calibrationDuration:1e3},vad:{enabled:!1,windowSize:5,estimatedLatencyMs:250,enableVoiceFilter:!0}}}}async destroyWaveform(){console.warn("destroyWaveform is not supported on web platform. No waveform resources to clean up.")}async preloadTracks(e){console.warn("preloadTracks is not supported on web platform. For web implementation, consider using HTML5 Audio API directly.");return{tracks:e.tracks.map(e=>({url:e,loaded:!1}))}}async playAudio(){throw console.warn("playAudio is not supported on web platform. For web implementation, consider using HTML5 Audio API directly."),new Error("playAudio is not supported on web platform")}async pauseAudio(){throw console.warn("pauseAudio is not supported on web platform. For web implementation, consider using HTML5 Audio API directly."),new Error("pauseAudio is not supported on web platform")}async resumeAudio(){throw console.warn("resumeAudio is not supported on web platform. For web implementation, consider using HTML5 Audio API directly."),new Error("resumeAudio is not supported on web platform")}async stopAudio(){throw console.warn("stopAudio is not supported on web platform. For web implementation, consider using HTML5 Audio API directly."),new Error("stopAudio is not supported on web platform")}async seekAudio(e){throw console.warn("seekAudio is not supported on web platform. For web implementation, consider using HTML5 Audio API directly."),new Error("seekAudio is not supported on web platform")}async skipToNext(){throw console.warn("skipToNext is not supported on web platform. For web implementation, consider using HTML5 Audio API directly."),new Error("skipToNext is not supported on web platform")}async skipToPrevious(){throw console.warn("skipToPrevious is not supported on web platform. For web implementation, consider using HTML5 Audio API directly."),new Error("skipToPrevious is not supported on web platform")}async skipToIndex(e){throw console.warn("skipToIndex is not supported on web platform. For web implementation, consider using HTML5 Audio API directly."),new Error("skipToIndex is not supported on web platform")}async getPlaybackInfo(){throw console.warn("getPlaybackInfo is not supported on web platform. For web implementation, consider using HTML5 Audio API directly."),new Error("getPlaybackInfo is not supported on web platform")}async setGainFactor(e){return console.warn(`setGainFactor is not supported on web platform. Attempted to set gain factor: ${e.gainFactor}`),{success:!1,gainFactor:e.gainFactor}}async openSettings(){console.warn("openSettings is not fully supported on web platform. Showing alert with instructions.");alert('To manage app permissions:\n\n1. Click the lock icon in your browser\'s address bar\n2. Select "Site settings" or "Permissions"\n3. Adjust microphone and other permissions as needed\n\nOr access browser settings directly through the browser menu.')}}var w=Object.freeze({__proto__:null,CapacitorAudioEngineWeb:m});exports.CapacitorAudioEngine=l,exports.base64ToBlob=function(e){const o=u(e),r=atob(o.data),t=new Array(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);const n=new Uint8Array(t);return new Blob([n],{type:o.mimeType})},exports.getCompressionInfo=function(e){const o=u(e);if(!o.isCompressed)return{isCompressed:!1};const r=Math.floor(3*o.data.length/4);return{isCompressed:!0,algorithm:o.algorithm,compressedSize:r}},exports.getDataURL=function(e){return e.startsWith("data:")?e:`data:audio/m4a;base64,${e}`},exports.getRawBase64Data=function(e){return u(e).data},exports.isCompressedBase64=function(e){return u(e).isCompressed},exports.parseBase64Data=u;