oceansweep
commited on
Commit
•
7708101
1
Parent(s):
530424e
Upload 2 files
Browse files
App_Function_Libraries/Audio_Files.py
CHANGED
@@ -30,11 +30,11 @@ from App_Function_Libraries.Audio_Transcription_Lib import speech_to_text
|
|
30 |
from App_Function_Libraries.Chunk_Lib import improved_chunking_process
|
31 |
#
|
32 |
# Local Imports
|
33 |
-
from App_Function_Libraries.DB_Manager import add_media_to_database, add_media_with_keywords, \
|
34 |
check_media_and_whisper_model
|
35 |
from App_Function_Libraries.Summarization_General_Lib import save_transcription_and_summary, perform_transcription, \
|
36 |
perform_summarization
|
37 |
-
from App_Function_Libraries.Utils import create_download_directory, save_segments_to_json, downloaded_files, \
|
38 |
sanitize_filename
|
39 |
from App_Function_Libraries.Video_DL_Ingestion_Lib import extract_metadata
|
40 |
|
|
|
30 |
from App_Function_Libraries.Chunk_Lib import improved_chunking_process
|
31 |
#
|
32 |
# Local Imports
|
33 |
+
from App_Function_Libraries.DB.DB_Manager import add_media_to_database, add_media_with_keywords, \
|
34 |
check_media_and_whisper_model
|
35 |
from App_Function_Libraries.Summarization_General_Lib import save_transcription_and_summary, perform_transcription, \
|
36 |
perform_summarization
|
37 |
+
from App_Function_Libraries.Utils.Utils import create_download_directory, save_segments_to_json, downloaded_files, \
|
38 |
sanitize_filename
|
39 |
from App_Function_Libraries.Video_DL_Ingestion_Lib import extract_metadata
|
40 |
|
App_Function_Libraries/Audio_Transcription_Lib.py
CHANGED
@@ -4,8 +4,6 @@
|
|
4 |
# This library is used to perform transcription of audio files.
|
5 |
# Currently, uses faster_whisper for transcription.
|
6 |
#
|
7 |
-
####
|
8 |
-
import configparser
|
9 |
####################
|
10 |
# Function List
|
11 |
#
|
@@ -21,11 +19,12 @@ import logging
|
|
21 |
import os
|
22 |
import sys
|
23 |
import subprocess
|
|
|
24 |
import time
|
25 |
-
|
26 |
# DEBUG Imports
|
27 |
#from memory_profiler import profile
|
28 |
-
|
29 |
# Import Local
|
30 |
#
|
31 |
#######################################################################################################################
|
@@ -187,6 +186,41 @@ def speech_to_text(audio_file_path, selected_source_lang='en', whisper_model='me
|
|
187 |
logging.error("speech-to-text: Error transcribing audio: %s", str(e))
|
188 |
raise RuntimeError("speech-to-text: Error transcribing audio")
|
189 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
190 |
#
|
191 |
#
|
192 |
#######################################################################################################################
|
|
|
4 |
# This library is used to perform transcription of audio files.
|
5 |
# Currently, uses faster_whisper for transcription.
|
6 |
#
|
|
|
|
|
7 |
####################
|
8 |
# Function List
|
9 |
#
|
|
|
19 |
import os
|
20 |
import sys
|
21 |
import subprocess
|
22 |
+
import tempfile
|
23 |
import time
|
24 |
+
import configparser
|
25 |
# DEBUG Imports
|
26 |
#from memory_profiler import profile
|
27 |
+
import pyaudio
|
28 |
# Import Local
|
29 |
#
|
30 |
#######################################################################################################################
|
|
|
186 |
logging.error("speech-to-text: Error transcribing audio: %s", str(e))
|
187 |
raise RuntimeError("speech-to-text: Error transcribing audio")
|
188 |
|
189 |
+
|
190 |
+
def record_audio(duration, sample_rate=16000, chunk_size=1024):
|
191 |
+
p = pyaudio.PyAudio()
|
192 |
+
stream = p.open(format=pyaudio.paInt16,
|
193 |
+
channels=1,
|
194 |
+
rate=sample_rate,
|
195 |
+
input=True,
|
196 |
+
frames_per_buffer=chunk_size)
|
197 |
+
|
198 |
+
print("Recording...")
|
199 |
+
frames = []
|
200 |
+
|
201 |
+
for _ in range(0, int(sample_rate / chunk_size * duration)):
|
202 |
+
data = stream.read(chunk_size)
|
203 |
+
frames.append(data)
|
204 |
+
|
205 |
+
print("Recording finished.")
|
206 |
+
|
207 |
+
stream.stop_stream()
|
208 |
+
stream.close()
|
209 |
+
p.terminate()
|
210 |
+
|
211 |
+
return b''.join(frames)
|
212 |
+
|
213 |
+
def save_audio_temp(audio_data, sample_rate=16000):
|
214 |
+
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as temp_file:
|
215 |
+
import wave
|
216 |
+
wf = wave.open(temp_file.name, 'wb')
|
217 |
+
wf.setnchannels(1)
|
218 |
+
wf.setsampwidth(2)
|
219 |
+
wf.setframerate(sample_rate)
|
220 |
+
wf.writeframes(audio_data)
|
221 |
+
wf.close()
|
222 |
+
return temp_file.name
|
223 |
+
|
224 |
#
|
225 |
#
|
226 |
#######################################################################################################################
|