mirror of
https://github.com/MarkParker5/STARK.git
synced 2025-01-08 10:45:08 +02:00
Remove mp3 files, fuzzy recognition
This commit is contained in:
parent
32e808583b
commit
76e6ec9061
@ -15,6 +15,7 @@
|
||||
#
|
||||
|
||||
from abc import ABC, abstractmethod # for abstract class and methods
|
||||
from fuzzywuzzy import fuzz
|
||||
|
||||
class Command(ABC):
|
||||
_list = [] # list of all commands
|
||||
@ -88,13 +89,13 @@ class Command(ABC):
|
||||
chances[i] = 0
|
||||
for weight, words in obj.getKeywords().items():
|
||||
for word in words:
|
||||
if word in string:
|
||||
chances[i] += weight
|
||||
chances[i] += fuzz.partial_ratio(word, string) * weight
|
||||
print(chances)
|
||||
if( sum( chances.values() ) ):
|
||||
top = max( chances.values() ) / sum( chances.values() ) * 100
|
||||
else:
|
||||
return list[0]
|
||||
print(top)
|
||||
for i, chance in chances.items():
|
||||
if chance == max( chances.values() ):
|
||||
return list[i]
|
||||
|
@ -28,7 +28,6 @@ keywords = {}
|
||||
void = SmallTalk('Undefined', keywords)
|
||||
void.setStart(method)
|
||||
################################################################################
|
||||
################################################################################
|
||||
def method():
|
||||
now = datetime.datetime.now()
|
||||
hours = now.hour%12
|
||||
@ -95,9 +94,9 @@ def method():
|
||||
return f'Сейчас {get_str_num(hours%12, 0)} {str_hour}, {get_str_num(minutes, 1)} {str_minute}'
|
||||
|
||||
keywords = {
|
||||
5: ['который час', 'сколько времени', 'время', 'часов'],
|
||||
2: ['текущее', 'сейчас', 'час'],
|
||||
0.5: ['сколько']
|
||||
10: ['который час', 'сколько времени'],
|
||||
5: ['текущее', 'сейчас', 'час', 'время'],
|
||||
1: ['сколько']
|
||||
}
|
||||
ctime = SmallTalk('Current Time', keywords)
|
||||
ctime.setStart(method)
|
||||
|
Binary file not shown.
Binary file not shown.
@ -2,23 +2,39 @@ from google.cloud import texttospeech
|
||||
import os
|
||||
import pygame
|
||||
import time
|
||||
import mmap
|
||||
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "Text2Speech/archie-test-key.json"
|
||||
|
||||
class speech:
|
||||
def __init__(this, text, voice, path):
|
||||
this._text = text
|
||||
this._voice = voice
|
||||
this._path = path
|
||||
class Speech:
|
||||
_list = []
|
||||
def __init__(this, text, voice, path, standart = False):
|
||||
this._text = text
|
||||
this._voice = voice
|
||||
this._path = path
|
||||
this._standart = standart
|
||||
if(standart): Speech.append(this)
|
||||
|
||||
def speak(this):
|
||||
print(f'Говорю: {this._text}')
|
||||
pygame.mixer.init()
|
||||
pygame.mixer.music.load(this._path)
|
||||
pygame.mixer.music.play()
|
||||
while pygame.mixer.music.get_busy() == True:
|
||||
time.sleep(0.1)
|
||||
if( os.path.exists(this._path) ):
|
||||
print(f'Говорю: {this._text}')
|
||||
with open(this._path) as f:
|
||||
with mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ) as audio:
|
||||
pygame.mixer.init()
|
||||
pygame.mixer.music.load(audio)
|
||||
pygame.mixer.music.play()
|
||||
while pygame.mixer.music.get_busy():
|
||||
time.sleep(0.1)
|
||||
if(not this._standart): os.remove(this._path)
|
||||
|
||||
class engine:
|
||||
@staticmethod
|
||||
def append(obj):
|
||||
Speech._list.append(obj)
|
||||
|
||||
@staticmethod
|
||||
def getList():
|
||||
return Speech._list
|
||||
|
||||
class Engine:
|
||||
def __init__(this, name = 'ru-RU-Wavenet-B'):
|
||||
# os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "archie-test-key.json"
|
||||
this._name = name
|
||||
@ -29,13 +45,13 @@ class engine:
|
||||
name = name,
|
||||
ssml_gender = texttospeech.SsmlVoiceGender.FEMALE)
|
||||
|
||||
def generate(this, text):
|
||||
def generate(this, text, standart = False):
|
||||
dir = f'audio/{this._name}'
|
||||
path = f'{dir}/{text}.mp3'
|
||||
if( os.path.exists(path) ): return Speech(text, this._name, path, standart)
|
||||
synthesis_input = texttospeech.SynthesisInput(text=text)
|
||||
response = this._client.synthesize_speech(input = synthesis_input, voice = this._voice, audio_config = this._audio_config)
|
||||
dir = f'audio/{this._name}/'
|
||||
path = f'{dir}/{text}.mp3'
|
||||
if not os.path.exists(dir): os.makedirs(dir)
|
||||
if not os.path.exists(path):
|
||||
with open(path, 'wb') as out:
|
||||
out.write(response.audio_content)
|
||||
return speech(text, this._name, path)
|
||||
with open(path, 'wb') as out:
|
||||
out.write(response.audio_content)
|
||||
return Speech(text, this._name, path, standart)
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
audio/ru-RU-Wavenet-B/Привет.mp3
Normal file
BIN
audio/ru-RU-Wavenet-B/Привет.mp3
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user