Spaces:
Build error

File size: 4,241 Bytes
d6d168e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env python3
import subprocess
import sys
import os

def install_requirements():
    """Install all required packages"""
    print("Installing core requirements...")
    
    # Core requirements (no conflicts)
    core_packages = [
        'SpeechRecognition==3.10.0',
        'gTTS==2.4.0',
        'pyttsx3==2.90',
        'pydub==0.25.1',
        'numpy==1.24.3',
        'langdetect==1.0.9',
        'playsound==1.2.2',
        'requests==2.31.0',
    ]
    
    for package in core_packages:
        print(f"Installing {package}...")
        subprocess.check_call([sys.executable, '-m', 'pip', 'install', package])
    
    # Try to install googletrans (might have issues on some systems)
    print("\nTrying to install googletrans...")
    try:
        subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'googletrans==3.0.0'])
    except:
        print("Note: googletrans installation failed. Using alternative translation methods.")
    
    # Streamlit packages
    print("\nInstalling Streamlit packages...")
    streamlit_packages = [
        'streamlit==1.28.0',
        'streamlit-audio-recorder==0.0.2',
    ]
    
    for package in streamlit_packages:
        subprocess.check_call([sys.executable, '-m', 'pip', 'install', package])
    
    # Platform-specific installations
    print("\nInstalling platform-specific packages...")
    
    if sys.platform.startswith('linux'):
        try:
            subprocess.run(['sudo', 'apt-get', 'update'], check=True)
            subprocess.run(['sudo', 'apt-get', 'install', '-y', 
                          'portaudio19-dev', 'python3-pyaudio', 'ffmpeg'], 
                         check=True)
        except:
            print("Note: Some Linux packages may need manual installation")
            print("Run: sudo apt-get install portaudio19-dev python3-pyaudio ffmpeg")
    
    elif sys.platform == 'darwin':
        try:
            subprocess.run(['brew', 'install', 'portaudio', 'ffmpeg'], check=True)
        except:
            print("Note: Install portaudio and ffmpeg using: brew install portaudio ffmpeg")
    
    elif sys.platform == 'win32':
        print("For Windows, please manually install:")
        print("1. Microsoft Visual C++ Redistributable")
        print("2. FFmpeg from ffmpeg.org")
    
    # Try to install pyaudio (may need manual installation)
    print("\nTrying to install pyaudio...")
    try:
        subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'pyaudio'])
    except:
        print("Note: pyaudio may need manual installation:")
        print("Linux: sudo apt-get install python3-pyaudio")
        print("Mac: brew install portaudio && pip install pyaudio")
        print("Windows: Download from https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyaudio")

def check_installation():
    """Check if installation was successful"""
    print("\n" + "="*50)
    print("Checking installation...")
    
    packages_to_check = [
        ('speech_recognition', 'SpeechRecognition'),
        ('gtts', 'gTTS'),
        ('pyttsx3', 'pyttsx3'),
        ('streamlit', 'streamlit'),
    ]
    
    all_ok = True
    for import_name, package_name in packages_to_check:
        try:
            __import__(import_name)
            print(f"✓ {package_name}")
        except ImportError:
            print(f"✗ {package_name} - Not installed")
            all_ok = False
    
    return all_ok

def main():
    print("Setting up Voice Translation Agent...")
    print("=" * 50)
    
    install_requirements()
    
    if check_installation():
        print("\n" + "="*50)
        print("Setup completed successfully! 🎉")
    else:
        print("\n" + "="*50)
        print("Some packages failed to install. Please install them manually.")
    
    print("\nQuick Start Guide:")
    print("1. Run the console app: python voice_translation_agent.py")
    print("2. Run the web app: streamlit run app.py")
    print("\nTroubleshooting:")
    print("- If microphone doesn't work, check system permissions")
    print("- On Windows, install pyaudio from: https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyaudio")
    print("- For translation issues, ensure you have internet connection")

if __name__ == "__main__":
    main()