Ilyas KHIAT commited on
Commit
7220677
·
1 Parent(s): 0ca9674
.gitignore ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ __pycache__/
2
+ .env
3
+ .streamlit/.env
.streamlit/config.toml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ [server]
2
+ maxUploadSize = 5
3
+
4
+ [theme]
5
+ base="light"
6
+ primaryColor="#63abdf"
7
+ secondaryBackgroundColor="#fbf7f1"
8
+ textColor="#011166"
requirements.txt CHANGED
@@ -5,4 +5,5 @@ pydub
5
  numpy
6
  scipy
7
  textstat
8
- pymupdf
 
 
5
  numpy
6
  scipy
7
  textstat
8
+ pymupdf
9
+ openai
utils/audit/audit_audio.py CHANGED
@@ -3,6 +3,13 @@ import numpy as np
3
  import scipy.io.wavfile as wavfile
4
  from pydub import AudioSegment
5
  import io
 
 
 
 
 
 
 
6
 
7
  # Function to calculate SNR
8
  def calculate_snr(audio_data):
@@ -14,15 +21,21 @@ def calculate_snr(audio_data):
14
  return snr
15
 
16
  # Function to evaluate audio quality
17
- def evaluate_audio_quality(file):
18
  audio = AudioSegment.from_file(file)
19
  audio_data = np.array(audio.get_array_of_samples())
20
-
 
 
 
21
  # Calculate volume
22
  volume = audio.dBFS
23
 
24
  # Calculate SNR
25
  snr = calculate_snr(audio_data)
 
 
 
26
 
27
- return volume, snr
28
 
 
3
  import scipy.io.wavfile as wavfile
4
  from pydub import AudioSegment
5
  import io
6
+ import tiktoken
7
+ from transcript_audio import transcript_audio
8
+
9
+ def count_tokens(input_string: str) -> int:
10
+ tokenizer = tiktoken.get_encoding("cl100k_base")
11
+ tokens = tokenizer.encode(input_string)
12
+ return len(tokens)
13
 
14
  # Function to calculate SNR
15
  def calculate_snr(audio_data):
 
21
  return snr
22
 
23
  # Function to evaluate audio quality
24
+ def evaluate_audio_quality(file) -> dict:
25
  audio = AudioSegment.from_file(file)
26
  audio_data = np.array(audio.get_array_of_samples())
27
+
28
+ #number of minutes
29
+ duration = len(audio_data) / audio.frame_rate / 60
30
+
31
  # Calculate volume
32
  volume = audio.dBFS
33
 
34
  # Calculate SNR
35
  snr = calculate_snr(audio_data)
36
+
37
+ #get the transcription of the audio
38
+ transcription = transcript_audio(file)
39
 
40
+ return {"volume": volume, "SNR": snr,"transcription": transcription,"number_of_tokens": count_tokens(transcription),"duration": duration}
41
 
utils/audit/transcript_audio.py ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ from openai import OpenAI
2
+ client = OpenAI()
3
+
4
+
5
+ def transcript_audio(audio_file):
6
+ transcription = client.audio.transcriptions.create(
7
+ model="whisper",
8
+ file=audio_file
9
+ )
10
+ return transcription.text