admin管理员组

文章数量:1122846

Basically, I'm trying to build a way to interact with a finetuned chatgpt model via a headset. I've managed to make it work with tinylama, though for to me unknown reasons that doesn't work anymore either--it won't register microphone input even though there is a microphone connected. I'm not a programmer and most of the code i got by copy pasting either from openAI's tutorials or chatGPT4. The whole thing will be used for an art installation and at the present making it work for ten minutes in a go is all I need.

Not sure how useful it is but this is the code that tinylama worked with:

mport subprocess
from gtts import gTTS
import os
import speech_recognition as sr

def speak(text):
    if text:  # Check if the text is not empty or None
        tts = gTTS(text=text, lang='en')
        tts.save("response.mp3")
        os.system("mpg321 response.mp3")
    else:
        print("No text to speak.")
def listen():
    recognizer = sr.Recognizer()
    with sr.Microphone() as source:
        print("Please say something:")
        audio = recognizer.listen(source)
 try:
        text = recognizer.recognize_google(audio)
        print(f"You said: {text}")
        return text
    except sr.UnknownValueError:
        print("Sorry, I did not understand that.")
        return None
    except sr.RequestError as e:
        print(f"Could not request results; {e}")
        return None
def query_tinyllama(prompt):
    try:
        result = subprocess.run(['ollama', 'run', 'tinyllama', prompt], capture>
        print(f"TinyLlama response: {result.stdout.strip()}")
        return result.stdout.strip()
    except Exception as e:
        print(f"Error: {e}")
        return "Sorry, I could not process that request."

def main():
    speak("Hello, thank you for reaching out to the Spiritual Negligence Helpli>

    while True:
        user_input = listen()
        if user_input:
def main():
    # Add your startup message here
    speak("Hello, thank you for reaching out to the Spiritual Negligence Helpli>

    while True:
        user_input = listen()
        if user_input:
            response = query_tinyllama(user_input)
            if not response:
                response = "Sorry, I didn't catch that."  # Default response if>
            speak(response)

if __name__ == "__main__":
    main()

But now when I run it it doesn't pick up on the microphone input. It worked in august though.

本文标签: