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.18 kB
JavaScript
import{registerPlugin as o,WebPlugin as e}from"@capacitor/core";var r,n,t,s,i,a,p,c,d,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:","")}}function m(o){return l(o).data}function w(o){return l(o).isCompressed}function A(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}}function b(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})}function f(o){return o.startsWith("data:")?o:`data:audio/m4a;base64,${o}`}!function(o){o[o.VOICE_8K=8e3]="VOICE_8K",o[o.VOICE_16K=16e3]="VOICE_16K",o[o.STANDARD_22K=22050]="STANDARD_22K",o[o.CD_44K=44100]="CD_44K",o[o.HIGH_48K=48e3]="HIGH_48K"}(r||(r={})),function(o){o[o.MONO=1]="MONO",o[o.STEREO=2]="STEREO"}(n||(n={})),function(o){o[o.VERY_LOW=16e3]="VERY_LOW",o[o.LOW=32e3]="LOW",o[o.MEDIUM=64e3]="MEDIUM",o[o.HIGH=128e3]="HIGH",o[o.VERY_HIGH=256e3]="VERY_HIGH"}(t||(t={})),function(o){o.LOW="low",o.MEDIUM="medium",o.HIGH="high"}(s||(s={})),function(o){o[o.BARS_16=16]="BARS_16",o[o.BARS_32=32]="BARS_32",o[o.BARS_64=64]="BARS_64",o[o.BARS_128=128]="BARS_128",o[o.BARS_256=256]="BARS_256"}(i||(i={})),function(o){o[o.REALTIME=.02]="REALTIME",o[o.VERY_FAST=.05]="VERY_FAST",o[o.FAST=.1]="FAST",o[o.MEDIUM=.25]="MEDIUM",o[o.SLOW=.5]="SLOW",o[o.VERY_SLOW=1]="VERY_SLOW"}(a||(a={})),function(o){o[o.VERY_SENSITIVE=.005]="VERY_SENSITIVE",o[o.SENSITIVE=.01]="SENSITIVE",o[o.NORMAL=.02]="NORMAL",o[o.MODERATE=.04]="MODERATE",o[o.LESS_SENSITIVE=.06]="LESS_SENSITIVE",o[o.NOT_SENSITIVE=.1]="NOT_SENSITIVE"}(p||(p={})),function(o){o[o.MINIMAL=3]="MINIMAL",o[o.LOW=4]="LOW",o[o.NORMAL=5]="NORMAL",o[o.MEDIUM=8]="MEDIUM",o[o.HIGH=10]="HIGH",o[o.MAXIMUM=15]="MAXIMUM"}(c||(c={})),function(o){o[o.QUICK=500]="QUICK",o[o.NORMAL=1e3]="NORMAL",o[o.EXTENDED=2e3]="EXTENDED",o[o.LONG=3e3]="LONG"}(d||(d={})),function(o){o[o.MINIMAL=5]="MINIMAL",o[o.LOW=10]="LOW",o[o.STANDARD=15]="STANDARD",o[o.MEDIUM=20]="MEDIUM",o[o.HIGH=30]="HIGH",o[o.MAXIMUM=50]="MAXIMUM"}(u||(u={}));const I=o("CapacitorAudioEngine",{web:()=>Promise.resolve().then(function(){return E}).then(o=>new o.CapacitorAudioEngineWeb)});var E=Object.freeze({__proto__:null,CapacitorAudioEngineWeb:class extends e{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.')}}});export{t as AudioBitrate,n as AudioChannels,s as AudioQuality,r as AudioSampleRate,d as CalibrationDuration,I as CapacitorAudioEngine,u as GainFactor,p as SpeechThreshold,c as VADWindowSize,i as WaveformBarsCount,a as WaveformDebounceTime,b as base64ToBlob,A as getCompressionInfo,f as getDataURL,m as getRawBase64Data,w as isCompressedBase64,l as parseBase64Data};