arnabg95 commited on
Commit
82f2206
1 Parent(s): b4a191d

model updated

Browse files
app/passing.py CHANGED
@@ -17,10 +17,10 @@ def calculate_passing(sequence, phonetic, cosine=0, euclidean=0, passing_thresho
17
 
18
  # Calculate the weighted average
19
  weights = {
20
- 'sequence': 0.50,
21
- 'phonetic': 0.50,
22
- 'cosine': 0,
23
- 'euclidean': 0
24
  }
25
 
26
  weighted_score = (
 
17
 
18
  # Calculate the weighted average
19
  weights = {
20
+ 'sequence': 0.35,
21
+ 'phonetic': 0.35,
22
+ 'cosine': 0.15,
23
+ 'euclidean': 0.15
24
  }
25
 
26
  weighted_score = (
app/routers/V1/voice/voice_router.py CHANGED
@@ -23,25 +23,25 @@ async def transcribe_audio(
23
  ):
24
  try:
25
  # Validate URL
26
- # if not original_url.endswith(".wav"):
27
- # raise HTTPException(
28
- # status_code=status.HTTP_400_BAD_REQUEST,
29
- # detail="Invalid URL. Please provide a URL pointing to a wav file.",
30
- # )
31
 
32
- # # Download the audio file from the URL
33
- # response = requests.get(original_url)
34
- # if response.status_code != 200:
35
- # raise HTTPException(
36
- # status_code=status.HTTP_400_BAD_REQUEST,
37
- # detail="Unable to download the audio file from the URL.",
38
- # )
39
 
40
- # filename_original = f"audio_{int(time.time())}_original.wav"
41
 
42
- # # Save the downloaded file temporarily
43
- # with open(filename_original, "wb") as buffer:
44
- # buffer.write(response.content)
45
 
46
  # Read file bytes
47
  recorded_bytes = await recorded.read()
@@ -55,7 +55,8 @@ async def transcribe_audio(
55
  text = get_transcription(filename_recorded)
56
  text = clean_transcription(text)
57
  sequence, phonetic = match(matcher_text, text)
58
- weighted_score, is_passing = calculate_passing(sequence, phonetic)
 
59
  return JSONResponse(
60
  {
61
  "transcription": text,
@@ -65,7 +66,7 @@ async def transcribe_audio(
65
  )
66
  finally:
67
  # Clean up the temporary file
68
- # os.remove(filename_original)
69
  os.remove(filename_recorded)
70
 
71
  except Exception as e:
 
23
  ):
24
  try:
25
  # Validate URL
26
+ if not original_url.endswith(".wav"):
27
+ raise HTTPException(
28
+ status_code=status.HTTP_400_BAD_REQUEST,
29
+ detail="Invalid URL. Please provide a URL pointing to a wav file.",
30
+ )
31
 
32
+ # Download the audio file from the URL
33
+ response = requests.get(original_url)
34
+ if response.status_code != 200:
35
+ raise HTTPException(
36
+ status_code=status.HTTP_400_BAD_REQUEST,
37
+ detail="Unable to download the audio file from the URL.",
38
+ )
39
 
40
+ filename_original = f"audio_{int(time.time())}_original.wav"
41
 
42
+ # Save the downloaded file temporarily
43
+ with open(filename_original, "wb") as buffer:
44
+ buffer.write(response.content)
45
 
46
  # Read file bytes
47
  recorded_bytes = await recorded.read()
 
55
  text = get_transcription(filename_recorded)
56
  text = clean_transcription(text)
57
  sequence, phonetic = match(matcher_text, text)
58
+ Euclidean, Cosine = mfcc_similarty_check(filename_original, filename_recorded)
59
+ weighted_score, is_passing = calculate_passing(sequence, phonetic, Cosine, Euclidean)
60
  return JSONResponse(
61
  {
62
  "transcription": text,
 
66
  )
67
  finally:
68
  # Clean up the temporary file
69
+ os.remove(filename_original)
70
  os.remove(filename_recorded)
71
 
72
  except Exception as e: