Skip to content
TheChatArchiveThe Chat Archive
Claudeclaude-3-5-sonnet-20241022· AnthropicHugging Face LMArena Human Preference 140K

I am building a speech to text app in rust, using tauri 2.0 + react 19 for the frontend.…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with o4-mini-2025-04-16’s answer.
  1. User

    I am building a speech to text app in rust, using tauri 2.0 + react 19 for the frontend. I would like to know how you think I should structure my project to syncronise the state of the settings in between the different components in the React UI and the rust backend. Once the app is initialized each rust service has to receive the changes in real time.

  2. Claude Assistant

    Let me help you design a state management solution for your Tauri + React speech-to-text app. Here's a suggested approach:

    1. Frontend State Management
    // Using Jotai or Zustand for atomic state management
    import { atom } from 'jotai'
    
    type Settings = {
      sampleRate: number,
      audioDevice: string,
      language: string,
      // other settings...
    }
    
    const settingsAtom = atom<Settings>({
      sampleRate: 16000,
      audioDevice: 'default',
      language: 'en-US'
    })
    
    1. Tauri Commands Interface
    // lib.rs or main.rs
    #[tauri::command]
    async fn update_settings(settings: Settings) -> Result<(), String> {
        // Update settings in your Rust services
        AUDIO_SERVICE.write().await.update_settings(&settings)?;
        STT_SERVICE.write().await.update_settings(&settings)?;
        Ok(())
    }
    
    1. React Components
    function SettingsPanel() {
      const [settings, setSettings] = useAtom(settingsAtom)
      
      const updateSettings = async (newSettings: Partial<Settings>) => {
        const updatedSettings = { ...settings, ...newSettings }
        setSettings(updatedSettings)
        // Invoke Tauri command
        await invoke('update_settings', { settings: updatedSettings })
      }
      
      return (
        // Your settings UI
      )
    }
    
    1. Rust Services Pattern
    pub struct AudioService {
        settings: Arc<RwLock<Settings>>,
        // other fields...
    }
    
    impl AudioService {
        pub async fn update_settings(&mut self, new_settings: &Settings) -> Result<(), String> {
            let mut settings = self.settings.write().await;
            *settings = new_settings.clone();
            self.apply_settings().await?;
            Ok(())
        }
    }
    

    Key aspects of this design:

    1. Use an atomic state management solution (Jotai/Zustand) to avoid prop drilling and ensure consistent state across React components

    2. Implement a single source of truth for settings in your React app

    3. Use Tauri commands to bridge the frontend and backend

    4. Implement thread-safe settings storage in Rust using Arc<RwLock<>> for shared state

    5. Create a robust error handling system between frontend and backend

    Would you like me to elaborate on any of these aspects or discuss alternative approaches?

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.