-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
66 lines (51 loc) · 2.1 KB
/
main.py
File metadata and controls
66 lines (51 loc) · 2.1 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
#!/usr/bin/env python3
"""
This is a Python-based interface for interacting with the OpenAI GPT-3
assistant API using audio input from a microphone. It's a fun project that
I've been working on to explore the capabilities of the OpenAI API and
experiment with voice input.
"""
import logging_config
from assistant import Assistant
from transcription import TranscriptionHandler
from audio_recording import Recorder
import configparser
import os
def main():
# Load configuration from file
config = configparser.ConfigParser()
config_file = os.path.join(os.path.dirname(
os.path.abspath(__file__)), 'config.ini')
config.read(config_file)
# Set the logging level and if the logs should go to console
to_console = config.getboolean('general', 'TO_CONSOLE')
log_level = config.get('general', 'LOG_LEVEL')
logging_config.configure_logging(log_level, to_console)
# Would you like to keep the recorded audio file?
delete_audio = config.getboolean('general', 'DELETE_AUDIO')
# Give your assistant a name!
name = config.get('general', 'ASSISTANT_NAME')
howie = Assistant(name)
# openai needs api key. Comment if using hugging-chat
# howie.setup_assistant_openai()
# This will record your voice with the default input device of your machine
mic_recorder = Recorder()
mic_recorder.record(max_duration=10)
# Whisper tries to transcribe your recorded audio. All locally.
model = config.get('general', 'MODEL')
transcript = TranscriptionHandler()
transcript.load_speech_to_text_model(model)
transcript.transcribe_audio_file(
mic_recorder.filename, delete=delete_audio)
user_text = transcript.transcription["text"]
# The transcripted text is beeing sent to openAI
assistant_text = howie.response_hugging_chat(from_user=user_text)
# Print or log conversation
if not to_console:
print(f"From user to assistant:{user_text}")
if assistant_text:
print(f"From assistant to user: {assistant_text}")
else:
print(f"Upsi. No response from {name}")
if __name__ == '__main__':
main()