MycroftAI / mimic3

A fast local neural text to speech engine for Mycroft
GNU Affero General Public License v3.0
1.08k stars 103 forks source link

TypeError: Object of type set is not JSON serializable #23

Closed popey closed 2 years ago

popey commented 2 years ago

Describe the bug Visiting the mimic3 web page results in empty drop-down fields and errors in the terminal. I have made no changes to mimic3. It worked yesterday, and now no longer does.

To Reproduce Steps to reproduce the behaviour: On Kubuntu 22.10

cd ~/Source/mycroftai
sudo apt install python3.10-venv
git clone https://github.com/MycroftAI/mimic3
cd mimic3
./install.sh
source .venv/bin/activate
mimic3-server
http://0.0.0.0:59125

Opening the web page looks like this. Screenshot_20221012_095232 Output from the command line looks like this:

ERROR:mimic3_http.app:Object of type set is not JSON serializable
Traceback (most recent call last):
  File "/home/alan/Source/mycroftai/mimic3/.venv/lib/python3.10/site-packages/quart/app.py", line 1673, in full_dispatch_request
    result = await self.dispatch_request(request_context)
  File "/home/alan/Source/mycroftai/mimic3/.venv/lib/python3.10/site-packages/quart/app.py", line 1718, in dispatch_request
    return await self.ensure_async(handler)(**request_.view_args)
  File "/home/alan/Source/mycroftai/mimic3/mimic3_http/app.py", line 270, in api_voices
    return jsonify(voice_dicts)
  File "/home/alan/Source/mycroftai/mimic3/.venv/lib/python3.10/site-packages/quart/json/__init__.py", line 32, in jsonify
    return current_app.json.response(*args, **kwargs)
  File "/home/alan/Source/mycroftai/mimic3/.venv/lib/python3.10/site-packages/quart/json/provider.py", line 205, in response
    return self._app.response_class(self.dumps(object_, **dump_args), mimetype=self.mimetype)
  File "/home/alan/Source/mycroftai/mimic3/.venv/lib/python3.10/site-packages/quart/json/provider.py", line 171, in dumps
    return json.dumps(object_, **kwargs)
  File "/usr/lib/python3.10/json/__init__.py", line 238, in dumps
    **kw).encode(obj)
  File "/usr/lib/python3.10/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python3.10/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/home/alan/Source/mycroftai/mimic3/.venv/lib/python3.10/site-packages/quart/json/provider.py", line 114, in _default
    raise TypeError(f"Object of type {type(object_).__name__} is not JSON serializable")
TypeError: Object of type set is not JSON serializable

Expected behaviour The web page should show like this, and be usable. Screenshot_20221011_102217

Environment (please complete the following information):

Additional context Worth noting this exact setup on this machine worked perfectly yesterday. I know this because I wrote a blog post about it. I left mimic running on my laptop, changed network a couple of times, came home, and tried again, and now it's completely failing. I even wiped the folder and re-cloned and reinstalled as per the instructions above.

stuartlangridge commented 2 years ago

The issue can be replicated by hitting http://0.0.0.0:59125/api/voices directly. The problem is that the aliases key in a Voice returned from Mimic3TextToSpeechSystem.get_voices is a set, and sets can't be serialised to JSON. It can be seen at https://github.com/MycroftAI/mimic3/blob/master/mimic3_tts/tts.py#L237 that aliases are loaded from a file, if that file is present, and the type of the aliases member is made a set. However, if there's nothing to load from disk (as happens on the first ever run) then aliases aren't set and so the error doesn't occur. This probably needs fixing by making that aliases member a list or a tuple, or by poking the JSON serialiser used in jsonify to convert sets to and from lists when serialising and deserialising, but someone who understands the code will need to do that.

synesthesiam commented 2 years ago

Should be fixed in 0.2.4