Я протестировал «Простой пример» с github.com/kramcat/CharacterAI, и он работает.
Вот код:
Код: Выделить всё
async def main():
char = "ai token"
client = aiocai.Client('token')
me = await client.get_me()
async with await client.connect() as chat:
new, answer = await chat.new_chat(char, me.id)
speak(answer.text)
while True:
if os.path.exists("recorded_speech.wav"):
os.remove("recorded_speech.wav")
text = record()
print(text)
message = await chat.send_message(char, new.chat_id, text)
speak(f'{message.text}')
asyncio.run(main())
Код: Выделить всё
speak()Код: Выделить всё
record()Код: Выделить всё
textНо когда я добираюсь до сообщения = awaitchat.send_message(char, new.chat_id, text), он выдает мне это исключение:
Код: Выделить всё
Traceback (most recent call last):
File "C:\Users\Admin\Desktop\python\tts\brain.py", line 97, in
print(asyncio.run(main()))
File "C:\Users\Admin\AppData\Local\Programs\Python\Python312\Lib\asyncio\runners.py", line 194, in run
return runner.run(main)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python312\Lib\asyncio\runners.py", line 118, in run
return self._loop.run_until_complete(task)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python312\Lib\asyncio\base_events.py", line 685, in run_until_complete
return future.result()
File "C:\Users\Admin\Desktop\python\tts\brain.py", line 93, in main
message = await chat.send_message(char, new.chat_id, text)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python312\Lib\site-packages\characterai\aiocai\methods\chat2.py", line 360, in send_message
await self.ws.send(json.dumps(message))
File "C:\Users\Admin\AppData\Local\Programs\Python\Python312\Lib\site-packages\websockets\legacy\protocol.py", line 628, in send
await self.ensure_open()
File "C:\Users\Admin\AppData\Local\Programs\Python\Python312\Lib\site-packages\websockets\legacy\protocol.py", line 929, in ensure_open
raise self.connection_closed_exc()
websockets.exceptions.ConnectionClosedOK: sent 1000 (OK); then received 1000 (OK)
на самом деле я вообще не менял код «Простой пример» , просто заменил text = input('YOU: ') для простого распознавания голоса.
Подробнее здесь: https://stackoverflow.com/questions/793 ... t-shouldnt
Мобильная версия