Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fb/estebanways #328

Merged
merged 3 commits into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion assets/docs/Keyboard Shortcuts Cheat Sheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ CTRL X Cut.
`Prefix` + `B` , `1-9` : Switch windows by their number IDs.
<br />`Prefix` + `B` , `Q` : Display pane numbers.
<br />`Prefix` + `B` , `SHIFT` : Split pane vertically.
<br />`Prefix` + `B` , `ARROWS` : Resize the active pane.
<br />`Prefix` + `B` + `ARROWS` : Resize the active pane.
<br />`Prefix` + `B` , `ARROWS` : Switch panes.

Default Prefix = CTRL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
# program downloads it automatically.
# Requires to run redirecting the standard error output (stderr) to the null
# device (/dev/null) like this to avoid ALSA output messages:
# python commbase_stt_whisper_p.py 2>& /dev/null
# shell> python commbase_stt_whisper_p.py 2>& /dev/null

# Requirements
import io
Expand All @@ -49,7 +49,7 @@

# A temporary directory and a file path within that directory
temp_file = tempfile.mkdtemp()
save_path = os.path.join(temp_file, "temp.wav")
save_path = os.path.join(temp_file, 'temp.wav')


def listen():
Expand All @@ -60,16 +60,18 @@ def listen():
the path of the saved audio file.
"""
listener = sr.Recognizer() # Create an instance of Recognizer
try:
with sr.Microphone() as source:
print("END USER:")
listener.adjust_for_ambient_noise(source)
audio = listener.listen(source)
with sr.Microphone() as source:
print("COMMBASE: Listening...")
listener.adjust_for_ambient_noise(source)

try:
audio = listener.listen(source, timeout=2) # Set a timeout of 2 seconds
print("COMMBASE: Processing...")
data = io.BytesIO(audio.get_wav_data())
audio_clip = AudioSegment.from_file(data)
audio_clip.export(save_path, format="wav")
except Exception as e:
print(e)
audio_clip.export(save_path, format='wav')
except sr.WaitTimeoutError:
print("COMMBASE: Speech stopped. Recognizing...")
return save_path


Expand All @@ -79,21 +81,22 @@ def recognize_audio(save_path):
transcribes an audio file located at save_path using that model. It then
returns the transcribed text extracted from the transcription result.
"""
audio_model = whisper.load_model("base") # The version of the Whisper model to load
transcription = audio_model.transcribe(save_path, language="english", fp16=False)
return transcription["text"]
audio_model = whisper.load_model('base')
transcription = audio_model.transcribe(save_path, language='english', fp16=False)
return transcription['text']


def main():
"""
Servers as the entry point of the program and orchestrates the speech
Serves as the entry point of the program and orchestrates the speech
recognition process.
"""
response = recognize_audio(listen())
print(response)
while True:
response = recognize_audio(listen())
print(f"END USER: {response}")


# Ensure that the main() function is executed only when the script is run
# directly as the main program.
if __name__ == "__main__":
if __name__ == '__main__':
main()
Empty file.