File size: 3,192 Bytes
ed3c183
e52cb87
 
 
ed3c183
e52cb87
 
 
 
 
 
 
 
 
 
 
ed3c183
 
e52cb87
 
 
 
ed3c183
 
 
e52cb87
 
 
 
ed3c183
 
e52cb87
 
 
 
 
 
1157a1c
e52cb87
 
 
1157a1c
e52cb87
 
 
 
 
 
 
ed3c183
e52cb87
ed3c183
e52cb87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import streamlit as st
from voice_handler import VoiceHandler
from memory_handler import MemoryHandler
from gemini_processor import GeminiProcessor

def render_voice_input(voice_handler, language_option, language_mapping, memory_handler, gemini_processor):
    """Render the voice input section with improved error handling"""
    
    st.markdown("""
    ### 🎤 Voice Input Requirements
    - Use Chrome, Firefox, or Edge browser
    - Grant microphone permissions when prompted
    - Ensure microphone is connected and working
    """)
    
    # Display voice input instructions based on language
    if language_option == "Arabic":
        st.markdown("""
        ### تعليمات الإدخال الصوتي:
        1. اضغط على زر "بدء التسجيل"
        2. تحدث بوضوح في الميكروفون
        3. سيتم معالجة كلامك تلقائياً
        """)
    else:
        st.markdown("""
        ### Voice Input Instructions:
        1. Click the "Start Recording" button
        2. Speak clearly into your microphone
        3. Your speech will be processed automatically
        """)
    
    # Check microphone access before showing the record button
    mic_status, mic_message = voice_handler.check_microphone_access()
    if not mic_status:
        st.error(mic_message)
        st.markdown("""
        ### 🔍 Microphone Access Guide
        
        1. Look for the camera/lock icon in your browser's address bar
        2. Click it and select "Allow" for microphone access
        3. Refresh the page
        
        If still not working:
        - Try a different browser (Chrome recommended)
        - Check if microphone works in other applications
        - Verify system sound settings
        - Restart your browser
        """)
        return
    
    col1, col2 = st.columns([1, 4])
    with col1:
        if st.button("🎤 Start Recording"):
            selected_language = language_mapping.get(language_option, "en-US")
            with st.spinner("Listening..."):
                voice_input = voice_handler.listen_for_voice(selected_language)
                
                if not voice_input.startswith("Error") and not voice_input.startswith("Could not"):
                    memory_handler.add_interaction(voice_input)
                    with st.spinner("Processing voice input..."):
                        context = memory_handler.get_context()
                        details = gemini_processor.extract_request_details(voice_input, context)
                        
                        if details:
                            st.session_state['voice_details'] = details
                            if 'translated_text' in details:
                                st.info(f"Translated text: {details['translated_text']}")
                            if details.get('missing_fields'):
                                missing = ", ".join(details['missing_fields'])
                                st.warning(f"Please provide the following missing information: {missing}")
                            else:
                                st.success("Voice input processed! Please verify the details below.")