-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
87 lines (73 loc) · 3.26 KB
/
Copy pathmain.py
File metadata and controls
87 lines (73 loc) · 3.26 KB
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
import time
from dotenv import load_dotenv
from src.audio_capture import AudioCapture
from src.speech_recognizer import SpeechRecognizer
from src.chatgpt_integration import ChatGPTIntegration
import os
import numpy as np
from src.gui import InterviewAssistantGUI
import json
import sys
import platform
from PyQt6.QtWidgets import QApplication
def check_dependencies():
try:
import openai
import sounddevice
from PyQt6.QtWidgets import QApplication
except ImportError as e:
print(f"Ошибка: {e}")
if platform.system() == "Windows":
print("Пожалуйста, запустите setup.bat для установки всех зависимостей.")
else:
print("Пожалуйста, запустите setup.sh для установки всех зависимостей.")
sys.exit(1)
def main():
check_dependencies()
load_dotenv()
if not os.getenv("OPENAI_API_KEY"):
print("Ошибка: API ключ OpenAI не найден в файле .env")
print("Пожалуйста, добавьте ваш API ключ в файл .env")
sys.exit(1)
audio_capture = AudioCapture()
chatgpt = ChatGPTIntegration()
recognizer = SpeechRecognizer()
app = QApplication(sys.argv)
def start_recording():
settings = window.get_settings()
audio_capture.device_index = int(settings['audio_device'])
chatgpt.set_model(settings['model'])
chatgpt.set_system_prompt(settings['prompt'])
recognizer.set_language(settings['language'])
audio_capture.start_recording()
debug_message = "Запись начата...\n"
debug_message += f"Используемая модель ChatGPT: {settings['model']}"
window.update_debug(debug_message)
def stop_recording():
audio_capture.stop_recording()
window.update_debug("Запись остановлена. Обработка аудио...")
audio_data = audio_capture.get_audio_data()
if audio_data is not None:
try:
audio_bytes = audio_data.tobytes()
transcript = recognizer.transcribe_audio(audio_bytes)
window.update_debug(f"Транскрибированный текст: {transcript}")
window.update_transcription(transcript)
settings = window.get_settings()
window.update_debug(
f"Отправка запроса к модели ChatGPT: {settings['model']}")
suggestion = chatgpt.get_response(transcript)
window.update_debug(f"Подсказка от ChatGPT: {suggestion}")
window.update_suggestion(suggestion)
except Exception as e:
error_message = f"Ошибка во время транскрибации или получения подсказки: {e}"
print(error_message)
window.update_debug(error_message)
else:
window.update_debug("Аудиоданные не захвачены.")
window = InterviewAssistantGUI(
audio_capture, chatgpt, start_recording, stop_recording)
window.show()
sys.exit(app.exec())
if __name__ == "__main__":
main()