OpenInterpreter / 01

The #1 open-source voice interface for desktop, mobile, and ESP32 chips.
https://01.openinterpreter.com/
GNU Affero General Public License v3.0
4.92k stars 517 forks source link

Fix UnboundLocalError for asset_url on Piper install (macOS) #175

Closed dheavy closed 6 months ago

dheavy commented 6 months ago

Problem

Fixes the following error occurring when installing Piper TTS:

urllib.request.urlretrieve(asset_url, os.path.join(PIPER_FOLDER_PATH, PIPER_ASSETNAME))
UnboundLocalError: local variable 'asset_url' referenced before assignment

It constantly happens on macOS, preventing first run of the poetry run 01 --local command. It is seems to be happening on Windows as well (see https://github.com/OpenInterpreter/01/issues/167#issuecomment-2024628495).

Solution

Setting the asset_url variable before using it.

How To Test

  1. Proceed with a first time install on macOS.
  2. Run Ollama or LM Studio with a model in the background.
  3. Run poetry run 01 --local from the software directory.

Discussion

Fix from #170 seemingly created a small regression by setting the value for asset_url in a Windows-only code-block.

stiliajohny commented 6 months ago

LGTM !

dheavy commented 6 months ago

I see the root cause. Can you just add OS = "windows" between line 50 and 51? See that there is a case problem?

Ah! Saw it! Thanks. Ensuring in the fix that the returned value is always deterministic (lower case).

Not sure how this got past me on the original commit. Thank you for your work on this!

No worries! My pleasure!

Note I have purposely not applied linter's results to this PR because it would apply to many unrelated changes. I believe it should be done in a different PR.

tyfiero commented 6 months ago

Great catch @dheavy, and thanks for assisting @TashaSkyUp!

hpsaturn commented 6 months ago

I have a similar error message:

UnboundLocalError: local variable 'asset_url' referenced before assignment
Complete output (click me) ``` [?] Select a downloaded Ollama model: > llama2 Using Ollama model: llama2 Exception in thread Thread-9: Traceback (most recent call last): File "/usr/lib/python3.9/threading.py", line 954, in _bootstrap_inner self.run() File "/usr/lib/python3.9/threading.py", line 892, in run self._target(*self._args, **self._kwargs) File "/usr/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete return future.result() File "/home/avp/tmp/src/openia_01/software/source/server/server.py", line 413, in main service_instance = ServiceClass(config) File "/home/avp/tmp/src/openia_01/software/source/server/services/tts/piper/tts.py", line 13, in __init__ self.install(config["service_directory"]) File "/home/avp/tmp/src/openia_01/software/source/server/services/tts/piper/tts.py", line 64, in install urllib.request.urlretrieve(asset_url, os.path.join(PIPER_FOLDER_PATH, PIPER_ASSETNAME)) UnboundLocalError: local variable 'asset_url' referenced before assignment ALSA lib pcm_dsnoop.c:638:(snd_pcm_dsnoop_open) unable to open slave ALSA lib pcm_dmix.c:1075:(snd_pcm_dmix_open) unable to open slave ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side ALSA lib pcm_oss.c:377:(_snd_pcm_oss_open) Unknown field port ALSA lib pcm_oss.c:377:(_snd_pcm_oss_open) Unknown field port ALSA lib pcm_a52.c:823:(_snd_pcm_a52_open) a52 is only for playback ALSA lib pcm_usb_stream.c:486:(_snd_pcm_usb_stream_open) Invalid type for card ALSA lib pcm_usb_stream.c:486:(_snd_pcm_usb_stream_open) Invalid type for card ALSA lib pcm_dmix.c:1075:(snd_pcm_dmix_open) unable to open slave Recording started... Recording stopped. ```

OS Details:

Distributor ID: Debian
Description:    Debian GNU/Linux 11 (bullseye)
Release:    11
Codename:   bullseye
TashaSkyUp commented 6 months ago

What OS are you using? and hardware architecture? looks like maybe linux? Have you pulled down the changes on main?

hpsaturn commented 6 months ago

Thanks for the fast response. I wrote the OS details in the previous comment. The last pull fix these problem, thanks, but now I have other. Let me check if maybe these errors are already reported...

TashaSkyUp commented 6 months ago

@hpsaturn if you know how can you run this in python for me and share the results?

OS = platform.system().lower()
ARCH = platform.machine()
print(OS,ARCH)
hpsaturn commented 6 months ago
#!/bin/python

import platform

OS = platform.system().lower()
ARCH = platform.machine()
print(OS,ARCH)

Output:

linux x86_64