Hunzla commited on
Commit
e50170f
1 Parent(s): 94d5e19

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -25
app.py CHANGED
@@ -1,20 +1,53 @@
1
  from transformers import pipeline
2
- asr_pipe = pipeline("automatic-speech-recognition", model="Abdullah17/whisper-small-urdu")
3
- from difflib import SequenceMatcher
4
 
5
- # List of commands
 
 
 
 
6
  commands = [
7
  "نمائندے ایجنٹ نمائندہ",
8
- " سم ایکٹیویٹ ",
9
- " سم بلاک بند ",
10
  "موبائل پیکیجز انٹرنیٹ پیکیج",
11
- " چالان جمع ",
12
- " گانا سنانا"
13
  ]
14
- # replies = [
15
- # 1,2,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  # ]
17
- # Function to find the most similar command
 
 
 
18
  def find_most_similar_command(statement, command_list):
19
  best_match = None
20
  highest_similarity = 0
@@ -29,21 +62,7 @@ def find_most_similar_command(statement, command_list):
29
  i+=1
30
 
31
  return best_match,reply
32
- def transcribe_the_command(audio):
33
- import soundfile as sf
34
- sample_rate, audio_data = audio
35
- file_name = "recorded_audio.wav"
36
- sf.write(file_name, audio_data, sample_rate)
37
- # Convert stereo to mono by averaging the two channels
38
- print(file_name)
39
-
40
- transcript = asr_pipe(file_name)["text"]
41
- most_similar_command,reply = find_most_similar_command(transcript, commands)
42
- print(f"Given Statement: {transcript}")
43
- print(f"Most Similar Command: {most_similar_command}\n")
44
- print(reply)
45
-
46
- return reply
47
  # get_text_from_voice("urdu.wav")
48
  import gradio as gr
49
 
 
1
  from transformers import pipeline
2
+ import soundfile as sf
 
3
 
4
+ # Load ASR model
5
+ asr_model = "Abdullah17/whisper-small-urdu"
6
+ asr_pipe = pipeline("automatic-speech-recognition", model=asr_model)
7
+
8
+ # Rest of your code
9
  commands = [
10
  "نمائندے ایجنٹ نمائندہ",
11
+ "سم ایکٹیویٹ",
12
+ "سم بلاک بند",
13
  "موبائل پیکیجز انٹرنیٹ پیکیج",
14
+ "چالان جمع",
15
+ "گانا سنانا"
16
  ]
17
+
18
+ # Function to transcribe the command from audio
19
+ def transcribe_the_command(audio_list):
20
+ transcriptions = []
21
+
22
+ # Process each audio in the batch
23
+ for audio_data, sample_rate in audio_list:
24
+ file_name = "recorded_audio.wav"
25
+ sf.write(file_name, audio_data, sample_rate)
26
+
27
+ # Convert stereo to mono by averaging the two channels
28
+ transcript = asr_pipe(file_name)[0]["text"]
29
+ most_similar_command, reply = find_most_similar_command(transcript, commands)
30
+
31
+ transcriptions.append((transcript, most_similar_command, reply))
32
+
33
+ return transcriptions
34
+ # from transformers import pipeline
35
+ # asr_pipe = pipeline("automatic-speech-recognition", model="Abdullah17/whisper-small-urdu")
36
+ # from difflib import SequenceMatcher
37
+
38
+ # # List of commands
39
+ # commands = [
40
+ # "نمائندے ایجنٹ نمائندہ",
41
+ # " سم ایکٹیویٹ ",
42
+ # " سم بلاک بند ",
43
+ # "موبائل پیکیجز انٹرنیٹ پیکیج",
44
+ # " چالان جمع ",
45
+ # " گانا سنانا"
46
  # ]
47
+ # # replies = [
48
+ # # 1,2,
49
+ # # ]
50
+ # # Function to find the most similar command
51
  def find_most_similar_command(statement, command_list):
52
  best_match = None
53
  highest_similarity = 0
 
62
  i+=1
63
 
64
  return best_match,reply
65
+ # x
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  # get_text_from_voice("urdu.wav")
67
  import gradio as gr
68