mirror of
https://github.com/jamiepine/voicebox.git
synced 2026-09-16 05:10:42 -07:00
- Replaced direct Tauri API calls with a unified platform context across multiple components, enhancing code maintainability and readability. - Removed the deprecated tauri.ts file, consolidating platform-related logic into the new PlatformContext. - Updated components such as App, AudioPlayer, and ServerSettings to utilize the new platform context for lifecycle management and server interactions. - Improved platform detection and handling for audio playback and system audio capture functionalities. - Ensured consistent error handling and user feedback across the application when interacting with platform-specific features.
46 lines
1.4 KiB
TypeScript
46 lines
1.4 KiB
TypeScript
import { invoke } from '@tauri-apps/api/core';
|
|
import type { PlatformAudio, AudioDevice } from '@/platform/types';
|
|
|
|
export const tauriAudio: PlatformAudio = {
|
|
isSystemAudioSupported(): boolean {
|
|
// This will be checked dynamically via invoke
|
|
return true; // Tauri supports it, but actual support depends on platform
|
|
},
|
|
|
|
async startSystemAudioCapture(maxDurationSecs: number): Promise<void> {
|
|
await invoke('start_system_audio_capture', {
|
|
maxDurationSecs,
|
|
});
|
|
},
|
|
|
|
async stopSystemAudioCapture(): Promise<Blob> {
|
|
const base64Data = await invoke<string>('stop_system_audio_capture');
|
|
|
|
// Convert base64 to Blob
|
|
const binaryString = atob(base64Data);
|
|
const bytes = new Uint8Array(binaryString.length);
|
|
for (let i = 0; i < binaryString.length; i++) {
|
|
bytes[i] = binaryString.charCodeAt(i);
|
|
}
|
|
|
|
return new Blob([bytes], { type: 'audio/wav' });
|
|
},
|
|
|
|
async listOutputDevices(): Promise<AudioDevice[]> {
|
|
return await invoke<AudioDevice[]>('list_audio_output_devices');
|
|
},
|
|
|
|
async playToDevices(audioData: Uint8Array, deviceIds: string[]): Promise<void> {
|
|
await invoke('play_audio_to_devices', {
|
|
audioData: Array.from(audioData),
|
|
deviceIds,
|
|
});
|
|
},
|
|
|
|
stopPlayback(): void {
|
|
invoke('stop_audio_playback').catch((error) => {
|
|
console.error('Failed to stop audio playback:', error);
|
|
});
|
|
},
|
|
};
|