PyCharacterAI icon indicating copy to clipboard operation
PyCharacterAI copied to clipboard

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

Open AritraMalik804 opened this issue 1 year ago • 0 comments

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'

AritraMalik804 avatar Jul 29 '24 13:07 AritraMalik804