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.43 kB
JavaScript
var capacitorNativeAudio=function(o,e){"use strict";var r,n,t,i,s,a,d,p,c,u;function l(o){if(!o.startsWith("data:"))return{isCompressed:!1,data:o,mimeType:"audio/m4a"};const[e,r]=o.split(",",2);return e.includes("lzfse:")?{isCompressed:!0,algorithm:"lzfse",data:r,mimeType:e.split(";")[0].replace("data:","")}:{isCompressed:!1,data:r,mimeType:e.split(";")[0].replace("data:","")}}o.AudioSampleRate=void 0,(r=o.AudioSampleRate||(o.AudioSampleRate={}))[r.VOICE_8K=8e3]="VOICE_8K",r[r.VOICE_16K=16e3]="VOICE_16K",r[r.STANDARD_22K=22050]="STANDARD_22K",r[r.CD_44K=44100]="CD_44K",r[r.HIGH_48K=48e3]="HIGH_48K",o.AudioChannels=void 0,(n=o.AudioChannels||(o.AudioChannels={}))[n.MONO=1]="MONO",n[n.STEREO=2]="STEREO",o.AudioBitrate=void 0,(t=o.AudioBitrate||(o.AudioBitrate={}))[t.VERY_LOW=16e3]="VERY_LOW",t[t.LOW=32e3]="LOW",t[t.MEDIUM=64e3]="MEDIUM",t[t.HIGH=128e3]="HIGH",t[t.VERY_HIGH=256e3]="VERY_HIGH",o.AudioQuality=void 0,(i=o.AudioQuality||(o.AudioQuality={})).LOW="low",i.MEDIUM="medium",i.HIGH="high",o.WaveformBarsCount=void 0,(s=o.WaveformBarsCount||(o.WaveformBarsCount={}))[s.BARS_16=16]="BARS_16",s[s.BARS_32=32]="BARS_32",s[s.BARS_64=64]="BARS_64",s[s.BARS_128=128]="BARS_128",s[s.BARS_256=256]="BARS_256",o.WaveformDebounceTime=void 0,(a=o.WaveformDebounceTime||(o.WaveformDebounceTime={}))[a.REALTIME=.02]="REALTIME",a[a.VERY_FAST=.05]="VERY_FAST",a[a.FAST=.1]="FAST",a[a.MEDIUM=.25]="MEDIUM",a[a.SLOW=.5]="SLOW",a[a.VERY_SLOW=1]="VERY_SLOW",o.SpeechThreshold=void 0,(d=o.SpeechThreshold||(o.SpeechThreshold={}))[d.VERY_SENSITIVE=.005]="VERY_SENSITIVE",d[d.SENSITIVE=.01]="SENSITIVE",d[d.NORMAL=.02]="NORMAL",d[d.MODERATE=.04]="MODERATE",d[d.LESS_SENSITIVE=.06]="LESS_SENSITIVE",d[d.NOT_SENSITIVE=.1]="NOT_SENSITIVE",o.VADWindowSize=void 0,(p=o.VADWindowSize||(o.VADWindowSize={}))[p.MINIMAL=3]="MINIMAL",p[p.LOW=4]="LOW",p[p.NORMAL=5]="NORMAL",p[p.MEDIUM=8]="MEDIUM",p[p.HIGH=10]="HIGH",p[p.MAXIMUM=15]="MAXIMUM",o.CalibrationDuration=void 0,(c=o.CalibrationDuration||(o.CalibrationDuration={}))[c.QUICK=500]="QUICK",c[c.NORMAL=1e3]="NORMAL",c[c.EXTENDED=2e3]="EXTENDED",c[c.LONG=3e3]="LONG",o.GainFactor=void 0,(u=o.GainFactor||(o.GainFactor={}))[u.MINIMAL=5]="MINIMAL",u[u.LOW=10]="LOW",u[u.STANDARD=15]="STANDARD",u[u.MEDIUM=20]="MEDIUM",u[u.HIGH=30]="HIGH",u[u.MAXIMUM=50]="MAXIMUM";const m=e.registerPlugin("CapacitorAudioEngine",{web:()=>Promise.resolve().then(function(){return A}).then(o=>new o.CapacitorAudioEngineWeb)});class w extends e.WebPlugin{async echo(o){return console.log("ECHO",o),o}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(o){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:o,start:e,end:r}){throw console.warn(`trimAudio is not supported on web platform. Attempted to trim file: ${o} from ${e}s to ${r}s. For web implementation, consider using Web Audio API directly.`),new Error("trimAudio is not supported on web platform")}async addListener(o,e){console.warn(`${o} 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(o){throw console.warn(`switchMicrophone is not supported on web platform. Attempted to switch to microphone ID: ${o.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(o){console.warn("preloadTracks is not supported on web platform. For web implementation, consider using HTML5 Audio API directly.");return{tracks:o.tracks.map(o=>({url:o,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(o){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(o){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(o){return console.warn(`setGainFactor is not supported on web platform. Attempted to set gain factor: ${o.gainFactor}`),{success:!1,gainFactor:o.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 A=Object.freeze({__proto__:null,CapacitorAudioEngineWeb:w});return o.CapacitorAudioEngine=m,o.base64ToBlob=function(o){const e=l(o),r=atob(e.data),n=new Array(r.length);for(let o=0;o<r.length;o++)n[o]=r.charCodeAt(o);const t=new Uint8Array(n);return new Blob([t],{type:e.mimeType})},o.getCompressionInfo=function(o){const e=l(o);if(!e.isCompressed)return{isCompressed:!1};const r=Math.floor(3*e.data.length/4);return{isCompressed:!0,algorithm:e.algorithm,compressedSize:r}},o.getDataURL=function(o){return o.startsWith("data:")?o:`data:audio/m4a;base64,${o}`},o.getRawBase64Data=function(o){return l(o).data},o.isCompressedBase64=function(o){return l(o).isCompressed},o.parseBase64Data=l,o}({},capacitorExports);