GoogleBard icon indicating copy to clipboard operation
GoogleBard copied to clipboard

Google Bard encountered an error

Open OH2912 opened this issue 11 months ago • 1 comments

Hi;

I was using the AI to make a Voice Assistant but encounter an error Below you can find my py file:

Google Bard encountered an error: b')]}'\n\n38\n[["wrb.fr",null,null,null,null,[9]]]\n56\n[["di",58],["af.httprm",58,"-8469647117787525651",16]]\n25\n[["e",4,null,null,131]]\n'.

from Bard import Chatbot from playsound import playsound import speech_recognition as sr from os import system import whisper import warnings import sys

token = "YOUR TOKEN" chatbot = Chatbot(token) r = sr.Recognizer()

tiny_model = whisper.load_model('tiny') base_model = whisper.load_model('base') warnings.filterwarnings("ignore", message="FP16 is not supported on CPU; using FP32 instead")

if sys.platform != 'darwin': import pyttsx3 engine = pyttsx3.init() rate = engine.getProperty('rate') engine.setProperty('rate', rate-50)

def prompt_bard(prompt): response = chatbot.ask(prompt) return response['content']

def speak(text): if sys.platform == 'darwin': ALLOWED_CHARS = set("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,?!-_$: ") clean_text = ''.join(c for c in text if c in ALLOWED_CHARS) system(f"say '{clean_text}'") else: engine.say(text) engine.runAndWait()

def main(): with sr.Microphone() as source: r.adjust_for_ambient_noise(source) while True: while True: try: print('\nSay "google" to wake me up. \n') audio = r.listen(source) with open("wake_detect.wav", "wb") as f: f.write(audio.get_wav_data()) result = tiny_model.transcribe('wake_detect.wav') text_input = result['text'] if 'google' in text_input.lower().strip(): break else: print("No wake word found. Try again.") except: print("Error transcribe audio: ", e) continue try: playsound('wake_detected.mp3') print("Wake word detected. Please speak your prompt to Bard. \n") audio = r.listen(source) with open("prompt.wav", "wb") as f: f.write(audio.get_wav_data()) result = base_model.transcribe('prompt.wav') prompt_text = result['text'] print("Sending to Bard:", prompt_text, '\n') if len(prompt_text.strip()) == 0: print("Empty prompt. Please speak again.") speak("Empty prompt. Please speak again.") continue except Exception as e: print("Error transcribing audio: ", e) continue response = prompt_bard(prompt_text) if sys.platform.startswith('win'): print('Bards response: ', response) else: print('Bards response: ', response) speak(response)

if name == 'main': main()

OH2912 avatar Jul 06 '23 12:07 OH2912