Error during translation and response: 'model'

I am trying to develop an python application to listen words and type, where it listens but when translate to a model it fails, is there any api limit? i used gemini api key.

import os
import speech_recognition as sr
from langchain_google_genai import ChatGoogleGenerativeAI
from gtts import gTTS
from playsound import playsound

translation = chat.generate_content(prompt=f"Translate this text to English: {text}“)
response_text = translation.result.candidates[0].content.parts[0].text
print(f"Translated text: {response_text}”)

Generate and play audio response

    tts = gTTS(text=response_text, lang=lang)
    tts.save("response.mp3")
    playsound("response.mp3")

Welcome to the forum.

You don’t show what was in variable {text} in the call to generate_content(). If that’s where you supplied the audio file, then that is the reason the code failed. Set up an array of Part (REST Resource: cachedContents  |  Google AI for Developers  |  Google for Developers). The first Part will have the text of your instruction. The second Part will be your audio file.

And, when using generate_content(), you can simply apply it to model, you don’t need the chat object.

Hope that helps. If not, please ask again and be more specific about what ‘failed’ means. What error code are you receiving?