import streamlit as st import speech_recognition as srec from gtts import gTTS import os import google.generativeai as genai from playsound import playsound # Google API Key (Replace with your actual key) GOOGLE_API_KEY = 'AIzaSyAc0urJKyqWaZsHc9ayF37IHVIeYQavIV0' # Configure Google AI Generative Model genai.configure(api_key=GOOGLE_API_KEY) model = genai.GenerativeModel('gemini-pro') def perintah(): mendengar = srec.Recognizer() with srec.Microphone() as source: st.write('Mendengarkan....') suara = mendengar.listen(source, phrase_time_limit=15) try: st.write('Diterima...') dengar = mendengar.recognize_google(suara, language='id-ID') st.write(f'Anda: {dengar}') # Generate response using Gemini Pro generative model chat = model.start_chat() response = chat.send_message(f'{dengar}') st.write(f'Nutrikara: {response.text}') return response.text except Exception as e: st.write(f'Error: {e}') return None def ngomong(teks): bahasa = 'id' namafile = 'Ngomong.mp3' teks_bersih = teks.replace('*', '|') def reading(): suara = gTTS(text=teks_bersih, lang=bahasa, slow=False) suara.save(namafile) playsound(namafile) reading() def run_michelle(): layanan = perintah() if layanan: ngomong(layanan) if __name__ == "__main__": st.subheader("Konsultasi Gizi Nutrikara") st.write("Klik tombol di bawah ini untuk mulai menggunakan:") if st.button("Mulai Konsultasi"): while True: run_michelle() layanan = perintah() break