-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEngine.py
More file actions
102 lines (74 loc) · 2.57 KB
/
Copy pathEngine.py
File metadata and controls
102 lines (74 loc) · 2.57 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import numpy as np
import sounddevice as sd
from pydub import AudioSegment
import os
from Google_S2T import google_S2T
from Audio_chop import audio_chop
from Groq_LLM import lecture_to_note
import Mongo_connect, Data_tableauhyper
################## Handle audio file ##################
global audio_queue
global audio_path
audio_queue = []
audio_path = ''
def audio_callback(indata, frames, time, status):
audio_queue.append(indata.copy())
stream = sd.InputStream(callback=audio_callback, samplerate=44100, channels=1)
def start_recording():
if not stream.active:
print("recording started")
stream.start()
def stop_recording():
global audio_queue
global audio_path
if stream.active:
print("recording stopped")
stream.stop()
stream.close()
audio_queue = np.concatenate(audio_queue, axis=0)
###### Normalize audio to [-1, 1] and scale to 16 bit integer
recorded_audio_data = np.int16(audio_queue / np.max(np.abs(audio_queue)) * 32767)
audio_segment = AudioSegment(
recorded_audio_data.tobytes(),
frame_rate=44100,
sample_width=recorded_audio_data.dtype.itemsize,
channels=1
)
audio_path = "recorded_audio.mp3"
audio_segment.export(audio_path)
def upload_recording(path):
global audio_path
audio_path = path.replace("\\", "\\\\")
print("you uploaded ", audio_path)
def split_audio():
global audio_path
global chunk_list
print("Splitting Audio to chunks...")
chunk_list = audio_chop(audio_path)
def speech2text():
global chunk_list
print("Converting Speech to text...")
lecture_text = ''
for each_path in chunk_list:
lecture_text += google_S2T(each_path) + ' '
with open("lecture_transcript.txt", 'w') as f:
f.write(lecture_text)
Mongo_connect.upload_transcript("lecture_transcript.txt")
def LLM_call():
global gen_data
print("Sending data to LLM to generate Note...")
gen_data = lecture_to_note("lecture_transcript.txt")
with open('Groq_ClassNote.md', 'w') as f:
f.write(gen_data)
Mongo_connect.upload_note('Groq_ClassNote.md')
return gen_data
def display_notes():
return Mongo_connect.list_notes()
def download_note(note_name):
content = Mongo_connect.pull_document(note_name)
print(f"Downloading {note_name}")
os.makedirs("Voc-Note Downloads", exist_ok=True)
with open(f"Voc-Note Downloads/{note_name}.md", 'w') as f:
f.write(content)
def gen_hyper():
Data_tableauhyper.create_hyper('lecture_transcript.txt')