forked from oobabooga/text-generation-webui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c09f416
commit 4c72e43
Showing
2 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
git+https://github.com/Uberi/speech_recognition.git@010382b | ||
PyAudio | ||
openai-whisper | ||
soundfile | ||
ffmpeg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import gradio as gr | ||
import speech_recognition as sr | ||
import modules.shared as shared | ||
|
||
input_hijack = { | ||
'state': False, | ||
'value': ["", ""] | ||
} | ||
|
||
|
||
def input_modifier(string): | ||
return string | ||
|
||
|
||
def do_stt(): | ||
transcription = "" | ||
r = sr.Recognizer() | ||
with sr.Microphone() as source: | ||
print("Say something!") | ||
r.adjust_for_ambient_noise(source) | ||
audio = r.listen(source) | ||
|
||
# recognize speech using whisper | ||
try: | ||
transcription = r.recognize_whisper(audio, language="english", model="tiny.en") | ||
print("Whisper thinks you said " + transcription) | ||
except sr.UnknownValueError: | ||
print("Whisper could not understand audio") | ||
except sr.RequestError as e: | ||
print("Could not request results from Whisper") | ||
|
||
# input_modifier(transcription) | ||
input_hijack.update({"state": True, "value": [transcription, transcription]}) | ||
return transcription | ||
|
||
|
||
def ui(): | ||
speech_button = gr.Button(value="STT") | ||
output_transcription = gr.Textbox(label="Speech Preview") | ||
speech_button.click(do_stt, outputs=[output_transcription]) |