Ki auf Raspberry Pi?

Hallo Leute ich habe ein Video bei YouTube gesehen wo einer einen gpt voice assistent in Python Code auf einen Raspberry Pi installiert und benutzt. Ich habe dass mal ausprobiert aus Spaß und hätte gerne gewusst wie man 1. Eine weibliche Stimme statt einer Männlichen Stimme benutzen kann und 2. Die Sprachausgabe in Deutsch einstellen kann habe den Python Code mal hier rein kopiert hoffe ihr könnt mir helfen. Ein paar Sachen habe ich wie zum Beispiel language en auf de umgestellt leider klappt dass nicht so ganz.

Danke im vorraus

import os

import openai

from dotenv import load_dotenv

import time

import speech_recognition as sr

import pyttsx3

import numpy as np

from gtts import gTTS

import subprocess

mytext = 'Welcome to me'

language = 'en'

# from os.path import join, dirname

# import matplotlib.pyplot as plt

# ^ matplotlib is great for visualising data and for testing purposes but usually not needed for production

openai.api_key=' '

load_dotenv()

model = 'gpt-3.5-turbo'

# Set up the speech recognition and text-to-speech engines

r = sr.Recognizer()

engine = pyttsx3.init("dummy")

voice = engine.getProperty('voices')[1]

engine.setProperty('voice', voice.id)

name = "YOUR NAME HERE"

greetings = [f"whats up master {name}",

       "yeah?",

       "Well, hello there, Master of Puns and Jokes - how's it going today?",

       f"Ahoy there, Captain {name}! How's the ship sailing?",

       f"Bonjour, Monsieur {name}! Comment ça va? Wait, why the hell am I speaking French?" ]

# Listen for the wake word "hey pos"

def listen_for_wake_word(source):

  print("Listening for 'Hey'...")

  while True:

    audio = r.listen(source)

    try:

      text = r.recognize_google(audio)

      if "hey" in text.lower():

        print("Wake word detected.")

        engine.say(np.random.choice(greetings))

        engine.runAndWait()

        listen_and_respond(source)

        break

    except sr.UnknownValueError:

      pass

# Listen for input and respond with OpenAI API

def listen_and_respond(source):

  print("Listening...")

  while True:

    audio = r.listen(source)

    try:

      text = r.recognize_google(audio)

      print(f"You said: {text}")

      if not text:

        continue

      # Send input to OpenAI API

      response = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=[{"role": "user", "content": f"{text}"}])

      response_text = response.choices[0].message.content

      print(response_text)

      #myobj = gTTS(text = response_text, lang = language, slow = False)

      #myobj.save("test.wav")

      #os.system("aplay test.wav")

      # Speak the response

      print("speaking")

      os.system("espeak ' "+response_text + "'")

      engine.say(response_text)

      engine.runAndWait()

      if not audio:

        listen_for_wake_word(source)

    except sr.UnknownValueError:

      time.sleep(2)

      print("Silence found, shutting up, listening...")

      listen_for_wake_word(source)

      break

    except sr.RequestError as e:

      print(f"Could not request results; {e}")

      engine.say(f"Could not request results; {e}")

      engine.runAndWait()

      listen_for_wake_word(source)

      break

# Use the default microphone as the audio source

with sr.Microphone() as source:

  listen_for_wake_word(source)

Code, künstliche Intelligenz, Python, ChatGPT
discord.py AttributeError: 'ClientUser' object has no attribute 'avatar_url'?
Hi, 

ich bau momentan einen discord Bot mit python der ein Formular strten soll.

Code:

@bot.command()
async def testform(ctx):
    form = Form(ctx,'Title')
    form.add_question('Question 1','first')
    form.add_question('Question 2','second')
    form.add_question('Question 3','third')
    await form.start()

Error:

2023-09-09 08:58:09 ERROR    discord.ext.commands.bot Ignoring exception in command testform
Traceback (most recent call last):
  File "/usr/local/python/3.10.4/lib/python3.10/site-packages/discord/ext/commands/core.py", line 235, in wrapped
    ret = await coro(*args, **kwargs)
  File "/workspaces/moon/dir/.py/homeworkBOT/main.py", line 43, in testform
    await form.start()
  File "/usr/local/python/3.10.4/lib/python3.10/site-packages/discord/ext/forms/form.py", line 221, in start
    embed.set_author(name=f"{self.title}: {n+1}/{len(self._questions)}", icon_url=self._bot.user.avatar_url)
AttributeError: 'ClientUser' object has no attribute 'avatar_url'


The above exception was the direct cause of the following exception:


Traceback (most recent call last):
  File "/usr/local/python/3.10.4/lib/python3.10/site-packages/discord/ext/commands/bot.py", line 1350, in invoke
    await ctx.command.invoke(ctx)
  File "/usr/local/python/3.10.4/lib/python3.10/site-packages/discord/ext/commands/core.py", line 1029, in invoke
    await injected(*ctx.args, **ctx.kwargs)  # type: ignore
  File "/usr/local/python/3.10.4/lib/python3.10/site-packages/discord/ext/commands/core.py", line 244, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'ClientUser' object has no attribute 'avatar_url'

Ich verstehe nicht was mit 'avatar_url' gemeint ist da ich diese nicht in meinem Code benutze.

Ich hoffe jemand kann mir helfen.

Code, Python, Forms, Python 3, Discord, Discord Bot

Meistgelesene Fragen zum Thema Python