/Gemini

Google Gemini AI model w/speech recognition and voice.

Primary LanguagePythonMIT LicenseMIT

FREE Reverse Engineering Self-Study Course HERE


Gemini

Google Gemini AI model w/speech recognition and voice.


Obtain API Key

HERE

Setup: Linux/MAC

Add API Environment Variable GOOGLE_GEMINI_API_KEY HERE

Install ffmpeg HERE

python3 -m venv venv
.\venv\Scripts\activate
pip install -r requirements.txt

Setup: Windows

Add API Environment Variable GOOGLE_GEMINI_API_KEY

export GOOGLE_GEMINI_API_KEY="<YOUR_GOOGLE_GEMINI_API_KEY>"

Install ffmpeg HERE

python3 -m venv venv
source venv/bin/active
pip install -r requirements.txt

Usage:

python gemini.py

gemini.py

import os
import subprocess
import pathlib
import textwrap
import google.generativeai as genai
from IPython.display import display, Markdown
from gtts import gTTS
import speech_recognition as sr

GOOGLE_GEMINI_API_KEY = os.environ['GOOGLE_GEMINI_API_KEY']
genai.configure(api_key=GOOGLE_GEMINI_API_KEY)
model = genai.GenerativeModel('gemini-pro')

while True:
	r = sr.Recognizer()
	mic = sr.Microphone()
	with mic as source:
		print("Speak now to Gemini...")
		audio = r.listen(source)
	text = r.recognize_google(audio)
	response = model.generate_content(text)
	speech = gTTS(response.text, lang='en')
	speech.save('output.mp3')
	process = subprocess.Popen(['ffplay', '-nodisp', '-autoexit', '-loglevel', 'quiet', 'output.mp3'],
		stdout=subprocess.DEVNULL,
		stderr=subprocess.DEVNULL)
	process.wait()

License

MIT