#๐Ÿ”’ Message won't print

21 messages ยท Page 1 of 1 (latest)

gaunt glen
#

I'm trying to have the online message print before I speak I'm not sure why it doesn't. I can show the full code if its needed but thats the specific part.

def main():
print("Online")
porcupine = None
pa = None
audio_stream = None

try:
    porcupine = pvporcupine.create(keywords=["jarvis"])
    pa = pyaudio.PyAudio()
    audio_stream = pa.open(
        rate=porcupine.sample_rate,
        channels=1,
        format=pyaudio.paInt16,
        input=True,
        frames_per_buffer=porcupine.frame_length)

    while True:
        pcm = audio_stream.read(porcupine.frame_length)
        pcm = struct.unpack_from("h" * porcupine.frame_length, pcm)
        keyword_index = porcupine.process(pcm)
        if keyword_index >= 0:
            action()
            time.sleep(1)
            print("Listening...")

finally:
    if porcupine is not None:
        porcupine.delete()

    if audio_stream is not None:
        audio_stream.close()

    if pa is not None:
        pa.terminate()

main()

near forgeBOT
#

@gaunt glen

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

tepid elbow
#

!code

near forgeBOT
#
Formatting code on Discord

Here's how to format Python code on Discord:

```py
print('Hello world!')
```

These are backticks, not quotes. Check this out if you can't find the backtick key.

For long code samples, you can use our pastebin.

gaunt glen
tepid elbow
#

if you follow the instructions in the message your code will get syntax highlighting

near forgeBOT
#

Hey @gaunt glen!

Please edit your message to use a code block

```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
gaunt glen
#
def main():
    print("Online")
    porcupine = None
    pa = None
    audio_stream = None


    try:
        porcupine = pvporcupine.create(keywords=["jarvis"])
        pa = pyaudio.PyAudio()
        audio_stream = pa.open(
            rate=porcupine.sample_rate,
            channels=1,
            format=pyaudio.paInt16,
            input=True,
            frames_per_buffer=porcupine.frame_length)

        while True:
            pcm = audio_stream.read(porcupine.frame_length)
            pcm = struct.unpack_from("h" * porcupine.frame_length, pcm)
            keyword_index = porcupine.process(pcm)
            if keyword_index >= 0:
                action()
                time.sleep(1)
                print("Listening...")

    finally:
        if porcupine is not None:
            porcupine.delete()

        if audio_stream is not None:
            audio_stream.close()

        if pa is not None:
            pa.terminate()

main()```
#

like that?

tepid elbow
#

no you forgot the py

gaunt glen
#

thanks

tepid elbow
#

why do you have it all in a try..finally block?

gaunt glen
#

do i not need that?

tepid elbow
#

if you can't name the reason you probably don't

gaunt glen
tepid elbow
#

@gaunt glensorry so what do you expect to be printed with this code?

gaunt glen
#

the whole wake word thing with pvporcupine doesnt work actually

near forgeBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.