def gettingWordsFromMic(): mic = Microphone() recognizer = Recognizer() print("Say something...") print(Microphone.list_microphone_names()) with mic as source: recognizer.adjust_for_ambient_noise(source) audio = recognizer.listen(source) input("Press a key to process") print(recognizer.recognize_google(audio))
def audio_to_text(message_input): # initialise the recognizer r = Recognizer() # Use the sysdefault microphone for i, microphone_name in enumerate(Microphone.list_microphone_names()): if microphone_name == "sysdefault": micro = Microphone(device_index=i) with micro as source: # Extract the audio and convert it to text audio = r.listen(source) # recognize speech using Google Speech Recognition and add it to the text input area try: message_input.setText(r.recognize_google(audio)) except UnknownValueError: message_input.setText('The audio was not understood')
from speech_recognition import Microphone for mic in Microphone.list_microphone_names(): print(mic)
def get_mic(): for index, mic in enumerate(Microphone.list_microphone_names()): if "usb" in mic.lower(): return Microphone(device_index=index) raise ValueError("USB microphone required to run.")
spotify = sp.Spotify(auth_manager=auth_manager) # Selecting device to play from devices = spotify.devices() deviceID = None for d in devices['devices']: d['name'] = d['name'].replace('’', '\'') if d['name'] == device_name: deviceID = d['id'] break # Setup microphone and speech recognizer r = Recognizer() m = None input_mic = 'Scarlett 2i4 USB' # Use whatever is your desired input for i, microphone_name in enumerate(Microphone.list_microphone_names()): if microphone_name == input_mic: m = Microphone(device_index=i) while True: """ Commands will be entered in the specific format explained here: - the first word will be one of: 'album', 'artist', 'play' - then the name of whatever item is wanted """ with m as source: r.adjust_for_ambient_noise(source=source) audio = r.listen(source=source) command = None try:
from speech_recognition import Microphone print(Microphone.list_microphone_names())