File size: 2,481 Bytes
baa1558
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#import library
import os
import time
import warnings
from caesarapis import CaesarAPIs
import speech_recognition as sr
warnings.filterwarnings("ignore")



#os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' 
# Initialize recognizer class (for recognizing the speech)


def speak(text,whisper_mode=0):
    if whisper_mode == 0:
        #espeak.synth(text)
        if "output.mp3" in os.listdir():
            os.remove("output.mp3")
        os.system(f'espeak "{text}" --stdout | ffmpeg -i pipe:0 output.mp3')        
        os.system(f'mplayer -volume 300 output.mp3')   
        os.system("pkill mplayer")     
        #raise KeyboardInterrupt
       #os.system(f'mplayer -af volume=30:1 output.mp3')
       
recognizer = sr.Recognizer()
# Reading Microphone as source
# listening the speech and store in audio_text variable
whisper_state = 1
caesarapis = CaesarAPIs()
while True:
    
        try:
            caesarintro ="How can I help you sir?" 
            print(caesarintro)
            #caesartalk(caesarintro,caesarapis.whisper_mode,filename="caesarintro.mp3")
            speak(caesarintro,caesarapis.whisper_mode)
            print("Listening...")

            with sr.Microphone() as source:
                recognizer.adjust_for_ambient_noise(source,duration=1)
                audio_text = recognizer.listen(source)

            #print("Billyy")
            #recognizer
            understood = "Understood sir, processing..."
            print(understood)
            #caesartalk(understood,caesarapis.whisper_mode,filename="caesar_understood.mp3")
            speak(understood,caesarapis.whisper_mode)
            # using google speech recognition
            text = recognizer.recognize_google(audio_text)
            print("output:",text)
            print("Caesar processing...")
            # TODO Send to Azure API
            if "hello" in text:
                print("Hola Amari")
                break
                #caesarResponse,intent = ("Hola Amari","greeting") 
                #caesarapis.runapis(caesarResponse,intent,text,speak)

                #print(f"User Input: {text}")
                #print(f"Caesar: {caesarResponse}")
                #caesartalk(caesarResponse,caesarapis.whisper_mode,filename="caesarResponse.mp3")
                #speak(caesarResponse,caesarapis.whisper_mode)
        except Exception as uex:
            continue


            # whisper_mode