mirror of
https://github.com/MarkParker5/STARK.git
synced 2025-01-18 11:12:15 +02:00
create SpeechRecognition
This commit is contained in:
parent
2f13700871
commit
6d235de619
@ -9,7 +9,7 @@ from Command import Command # import parent class
|
||||
|
||||
class SmallTalk(Command):
|
||||
def start(this, string): # main method
|
||||
print('Im using SmallTalk now :)')
|
||||
print('Hello, World!')
|
||||
|
||||
def confirm(this): # optional method
|
||||
return True
|
||||
|
34
SpeechRecognition/SpeechRecognition.py
Normal file
34
SpeechRecognition/SpeechRecognition.py
Normal file
@ -0,0 +1,34 @@
|
||||
import speech_recognition as sr
|
||||
import time
|
||||
|
||||
r = sr.Recognizer()
|
||||
m = sr.Microphone(device_index=1)
|
||||
|
||||
class SpeechToText:
|
||||
def __init__(this, device = 1, language = "ru-RU", pause_threshold = 0.5):
|
||||
this.device = 1
|
||||
this.language = language
|
||||
this.m = sr.Microphone(device_index = this.device)
|
||||
this.r = sr.Recognizer()
|
||||
this.r.pause_threshold = pause_threshold
|
||||
this.r.energy_threshold = 2000
|
||||
this.r.dynamic_energy_threshold = False
|
||||
|
||||
def listen(this):
|
||||
with this.m as source:
|
||||
audio = this.r.listen(source)
|
||||
try:
|
||||
responce = {'text': this.r.recognize_google(audio, language = this.language).lower(), 'status': 'ok'}
|
||||
except sr.UnknownValueError:
|
||||
responce = {'text': None, 'status': 'void'}
|
||||
except sr.RequestError:
|
||||
responce = {'text': None, 'status': 'error'}
|
||||
return responce
|
||||
|
||||
def listen_noise(this):
|
||||
with this.m as source:
|
||||
this.r.adjust_for_ambient_noise(source)
|
||||
|
||||
def set_device(this, index):
|
||||
this.device = 1
|
||||
this.m = sr.Microphone(device_index = this.device)
|
1
SpeechRecognition/__init__.py
Normal file
1
SpeechRecognition/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
from .SpeechRecognition import *
|
@ -36,7 +36,7 @@ class Speech:
|
||||
|
||||
class Engine:
|
||||
def __init__(this, name = 'ru-RU-Wavenet-B'):
|
||||
# os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "archie-test-key.json"
|
||||
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "Text2Speech/tts-gc-key.json"
|
||||
this._name = name
|
||||
this._client = texttospeech.TextToSpeechClient()
|
||||
this._audio_config = texttospeech.AudioConfig( audio_encoding = texttospeech.AudioEncoding.MP3 )
|
||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user