Spaces:
Sleeping
Sleeping
Commit
·
f808091
1
Parent(s):
9024b3e
update app.py
Browse files
app.py
CHANGED
|
@@ -1,64 +1,26 @@
|
|
| 1 |
-
import
|
| 2 |
-
import
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
#
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 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()
|