expo-sound-analysis
Version:
Expo plugin for iOS Sound Analysis
35 lines (29 loc) • 943 B
text/typescript
import { EventSubscription } from "expo-modules-core";
import ExpoSoundAnalyzer from "./SoundAnalyzer";
export interface SoundEvent {
type: string;
confidence: number;
timestamp: number;
}
export class SoundAnalyzer {
static async startAnalysis(): Promise<void> {
return await ExpoSoundAnalyzer.startAnalysis();
}
static async stopAnalysis(): Promise<void> {
return await ExpoSoundAnalyzer.stopAnalysis();
}
static async analyzeFile(uri: string): Promise<SoundEvent[]> {
try {
const results = await ExpoSoundAnalyzer.analyzeFile(uri);
return results; // Return the results array
} catch (error) {
console.error("Error analyzing file:", error);
throw error; // Re-throw the error for upstream handling
}
}
static addSoundListener(
listener: (event: SoundEvent) => void
): EventSubscription {
return ExpoSoundAnalyzer.addListener("onSoundDetected", listener);
}
}