1
0
mirror of https://github.com/MarkParker5/STARK.git synced 2025-01-18 11:12:15 +02:00

create SpeechRecognition

This commit is contained in:
MarkParker5 2020-07-17 23:24:40 +03:00
parent 2f13700871
commit 6d235de619
5 changed files with 37 additions and 2 deletions

View File

@ -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

View 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)

View File

@ -0,0 +1 @@
from .SpeechRecognition import *

View File

@ -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 )