Xtr4F / PyCharacterAI

An unofficial Python api wrapper for character.ai
https://character.ai/
MIT License
40 stars 11 forks source link

TypeError: argument should be a bytes-like object or ASCII string, not 'NoneType' #6

Closed NoOneIsHereExceptMe closed 2 months ago

NoOneIsHereExceptMe commented 4 months ago
import asyncio
from PyCharacterAI import Client

token = "<token>"

async def main():
    client = Client()
    await client.authenticate_with_token(token)

    username = (await client.fetch_user())['user']['username']
    print(f'Authenticated as {username}')

    character_id = "<An unlisted AI id>"
    chat = await client.create_chat(character_id)

    while True:
        message = input(f'{username}: ')  # In: Hi!

        answer = await chat.send_message(message)
        audio = await client.generate_voice(22, str.encode(answer.text))

        filepath = "voice.mp3"  # Path to the directory where you want to save the audio

        with open("voice.wav", 'wb') as f:
            f.write(audio.read())

        print(f"{answer.src_character_name}: {answer.text}")  # Out: hello there! what kind of question you gonna ask me ? i'm here to assist you :)

asyncio.run(main())

I used the default example they have given but it's giving me this error:

Authenticated as <my-username>
<my-username>: hello
Traceback (most recent call last):
  File "c:\Users\<user>\OneDrive\Documents\Python Projects\AKI2.0\speech.py", line 31, in <module>
    asyncio.run(main())
  File "C:\Users\<user>\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "C:\Users\<user>\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\<user>\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 654, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "c:\Users\<user>\OneDrive\Documents\Python Projects\AKI2.0\speech.py", line 21, in main
    audio = await client.generate_voice(22, str.encode(answer.text))
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\<user>\OneDrive\Documents\Python Projects\AKI2.0\.venv\Lib\site-packages\pycharacterai-1.1.0-py3.11.egg\PyCharacterAI\client.py", line 210, in generate_voice
  File "C:\Users\<user>\AppData\Local\Programs\Python\Python311\Lib\base64.py", line 83, in b64decode
    s = _bytes_from_decode_data(s)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\<user>\AppData\Local\Programs\Python\Python311\Lib\base64.py", line 45, in _bytes_from_decode_data
    raise TypeError("argument should be a bytes-like object or ASCII "
TypeError: argument should be a bytes-like object or ASCII string, not 'NoneType'
Xtr4F commented 2 months ago

Hi. At the time this issue was created, the library was very outdated. A lot of things have changed in the api over the last year, so I've released a new version 2.0 that fixes many bugs and includes many new features, but unfortunately breaks backwards compatibility. If you are still interested in this project, you can check out the new version and read the documentation.