-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanother_ai.py
32 lines (28 loc) · 940 Bytes
/
another_ai.py
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
import speech_recognition as sr
import os
from gtts import gTTS
import datetime
import warnings
import wikipedia
import random
import calendar
# -----------------------------------------------
# Ignore any warning messages
warnings.filterwarnings('ignore')
# record audio adn return it as a string
def recordAudio():
# record the audio
r = sr.Recognizer() # creating a recognizer object
# Open the microphone and start recording
with sr.Microphone as source:
print('say something')
audio = r.listen(source)
# use google speech recognition
data = ''
try:
data = r.recognize_google(audio)
print('You said: ' + data)
except sr.UnknownValueError: # Check for unknow errors
print("Google speech recognition could not understand the audio, unknown error")
except sr.RequestError as e:
print('Request result from Google speech recognition service error' + e)