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.
本文标签:
版权声明:本文标题:python - connecting a fine-tuned chatgpt model with vtt and tts via terminal in linux (raspberry pi) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736307684a1933399.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论