question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Porcupine Issue: syntax error raised when running porcupine_demo_mic

See original GitHub issue

Make sure you have read the documentation, and have put forth a reasonable effort to find an existing answer.

Expected behaviour

Unknown, code does not run

Actual behaviour

With environment variable ACCESS_KEY set to access key from picovoice account and with network access available.

$ porcupine_demo_mic --access_key ${ACCESS_KEY} --keywords porcupine
Traceback (most recent call last):
  File "/usr/local/bin/porcupine_demo_mic", line 6, in <module>
    from pvporcupinedemo.porcupine_demo_mic import main
  File "<fstring>", line 1
    (self._access_key=)
                     ^
SyntaxError: invalid syntax


With access code encoded in command

$ porcupine_demo_mic --access_key O6m<redacted middle of access code>4fg== --keywords porcupine
Traceback (most recent call last):
  File "/usr/local/bin/porcupine_demo_mic", line 6, in <module>
    from pvporcupinedemo.porcupine_demo_mic import main
  File "<fstring>", line 1
    (self._access_key=)
                     ^
SyntaxError: invalid syntax

Steps to reproduce the behaviour

Running on hyproit on RPi 3B+ which comes with python 3.7.3 Installed pvporcupine as per destructions at: https://picovoice.ai/docs/quick-start/porcupine-python/

Tried example python code but could not resolve issues I was finding it would not resolve the env to pick up the access key.

$ python
Python 3.7.3 (default, Dec 20 2019, 18:57:59)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pvporcupine
>>> porcupine = pvporcupine.create(
...   access_key='${ACCESS_KEY}',
...   keywords=['picovoice', 'bumblebee']
... )
[ERROR] failed to parse AccessKey '${ACCESS_KEY}'
Traceback (most recent call last):
  File "<stdin>", line 3, in <module>
  File "/usr/local/lib/python3.7/dist-packages/pvporcupine/__init__.py", line 82, in create
    sensitivities=sensitivities)
  File "/usr/local/lib/python3.7/dist-packages/pvporcupine/porcupine.py", line 158, in __init__
    raise self._PICOVOICE_STATUS_TO_EXCEPTION[status]()
pvporcupine.porcupine.PorcupineInvalidArgumentError
>>>

I tried embedding the key in the code and the code worked fine with access key embedded in the code, except the python code example was obviously stunted and not a full example.

Opted into using the demo at https://picovoice.ai/docs/quick-start/porcupine-python/#demo and so then arrived at the syntax error reported at the top.

Uninstalled everything then reinstalled but then got:


$ porcupine_demo_mic --access_key ${ACCESS_KEY} --keywords porcupine
-bash: /usr/local/bin/porcupine_demo_mic: No such file or directory

$ porcupine_demo_mic --access_key O6mlLw<redacted middle of key>ujA//WcHJ8w4fg== --keywords porcupine
-bash: /usr/local/bin/porcupine_demo_mic: No such file or directory

$ porcupine_demo_mic --help
-bash: /usr/local/bin/porcupine_demo_mic: No such file or directory
HypriotOS/armv7: pirate@silver-pearl in ~

As I was setting a new RPi with hyproit, I reburned the SD card from scratch and so the first thing I tried was pip3 install pvporcupinedemo and then

$ /home/pirate/.local/bin/porcupine_demo_mic --access_key O6mlLwkDR<redacted middle of key>BrujA//WcHJ8w4fg== --keywords porcupine
Traceback (most recent call last):
  File "/home/pirate/.local/bin/porcupine_demo_mic", line 6, in <module>
    from pvporcupinedemo.porcupine_demo_mic import main
  File "<fstring>", line 1
    (self._access_key=)
                     ^
SyntaxError: invalid syntax

I have tried no quotes, single and double quotes around the key - to same end result. Network has been up the entire time (and would need to be since I am sshing into the RPi and pulling down files using pip3).

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Bazmundicommented, Jan 26, 2022

So, I burned onto a SD:

Raspberry Pi OS Lite
Release date: October 30th 2021
Kernel version: 5.10

Setup wifi and ssh so I could get files from my PC (test.wav for example).

Ran:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get python3-pip
sudo pip3 install pvporcupinedemo

Python version that comes with:

pi@raspberrypi:~ $ python --version
Python 3.9.2

As for previous report, the demo versus the wav file worked. So this time did:

porcupine_demo_mic --access_key O6mlLwkDR8A<redact middle of key>jA//WcHJ8w4fg== --keywords porcupine --audio_device_index 1

So is this the difference between Python 3.7.3 that came with hypriot and the 3.9.2 that comes with RPi OS Lite? I’ll look into it.

0reactions
Bazmundicommented, Feb 4, 2022

@creating-worlds

Hmmm. Can’t help at the moment. https://github.com/Picovoice/porcupine/issues/653 so I’ve a few weeks left before I can try again. But isn’t it odd then that it looked like I had sorted my problem by installing 3.9.2 on hypriot, since it wasn’t apparently a problem on the Raspian OS, but then which Raspian version may be the question. Double hmmn.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Invalid Syntax in Python: Common Reasons for SyntaxError
When the interpreter encounters invalid syntax in Python code, it will raise a SyntaxError exception and provide a traceback with some helpful information...
Read more >
How to Fix Invalid SyntaxError in Python - Rollbar
The Python SyntaxError occurs when the interpreter encounters invalid syntax in code. Learn how to fix it.
Read more >
Run Python File in Terminal - syntax error · Issue #2248 - GitHub
Every time I right click and try to run edited python file a syntax error is raised from terminal. no issues so far...
Read more >
Python raise - SyntaxError when running as an executable
The error is: SyntaxError: invalid syntax pointing to the ' symbol at the end of the line. I do not understand how is...
Read more >
SyntaxError - JavaScript - MDN Web Docs
The SyntaxError object represents an error when trying to interpret syntactically invalid code. It is thrown when the JavaScript engine encounters tokens or ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found