SujanMidatani commited on
Commit
f808091
·
1 Parent(s): 9024b3e

update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -63
app.py CHANGED
@@ -1,64 +1,26 @@
1
- import requests
2
- import time
3
- import json
4
- import gradio as gr
5
- secret_key = "6d74a4fac397423a8bd3011180b9b979"
6
-
7
- # retrieve transcription results for the task
8
- def get_results(config):
9
- # endpoint to check status of the transcription task
10
- endpoint = "https://api.speechtext.ai/results?"
11
- # use a loop to check if the task is finished
12
- while True:
13
- results = requests.get(endpoint, params=config).json()
14
- if "status" not in results:
15
- break
16
- # print("Task status: {}".format(results["status"]))
17
- if results["status"] == 'failed':
18
- print("The task is failed: {}".format(results))
19
- break
20
- if results["status"] == 'finished':
21
- break
22
- # sleep for 15 seconds if the task has the status - 'processing'
23
- time.sleep(15)
24
- return results
25
-
26
- # loads the audio into memory
27
- def spt(audio_file):
28
- with open(audio_file, mode="rb") as file:
29
- post_body = file.read()
30
-
31
- # endpoint to start a transcription task
32
- endpoint = "https://api.speechtext.ai/recognize?"
33
- header = {'Content-Type': "application/octet-stream"}
34
-
35
- # transcription task options
36
- config = {
37
- "key" : secret_key,
38
- "language" : "en-US",
39
- "punctuation" : True,
40
- "format" : "m4a"
41
- }
42
-
43
- # send an audio transcription request
44
- r = requests.post(endpoint, headers = header, params = config, data = post_body).json()
45
-
46
- # get the id of the speech recognition task
47
- task = r["id"]
48
- # print("Task ID: {}".format(task))
49
-
50
- # get transcription results, summary, and highlights
51
- config = {
52
- "key" : secret_key,
53
- "task" : task,
54
- "summary" : True,
55
- "summary_size" : 15,
56
- "highlights" : True,
57
- "max_keywords" : 10
58
- }
59
-
60
- transcription = get_results(config)
61
- p=transcription['results']['transcript'].replace('<kw>','').replace('</kw>','')
62
- return p
63
- k=gr.Interface(fn=spt, inputs=gr.Audio(source="microphone", type="filepath"), outputs="text")
64
  k.launch()
 
1
+ import sounddevice as sd
2
+ import speech_recognition as sr
3
+ def takeCommand(audio):
4
+ r = sr.Recognizer()
5
+ with sr.AudioFile(
6
+ audio
7
+ ) as source: # Replace "audio.wav" with the path to your .wav file
8
+ # print("Listening...")
9
+ audio_data = r.record(source)
10
+
11
+ try:
12
+ # print("Recognizing...")
13
+ query = r.recognize_google(audio_data, language="en-in")
14
+ print(f"User said: {query}")
15
+ return query
16
+ except sr.UnknownValueError:
17
+ print("Unable to recognize speech")
18
+ except sr.RequestError as e:
19
+ print(f"Error occurred: {e}")
20
+
21
+ return "Some error occurred. Sorry from Jarvis"
22
+
23
+
24
+
25
+ k=gr.Interface(fn=takeCommand, inputs=gr.Audio(source="microphone", type="filepath"), outputs="text")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  k.launch()