#๐Ÿ”’ Need help with speech recognition

134 messages ยท Page 1 of 1 (latest)

magic cloudBOT
#

@faint finch

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.

#

:incoming_envelope: :ok_hand: applied timeout to @faint finch until <t:1733300573:f> (10 minutes) (reason: emoji spam - sent 24 emojis).

The <@&831776746206265384> have been alerted for review.

icy falcon
#

Shouldn't it be recognize_google_cloud

modern sierra
#

!unmute 973206297329688647

magic cloudBOT
#

:incoming_envelope: :ok_hand: pardoned infraction timeout for @faint finch.

modern sierra
#

@faint finch please use the pastebin for large content

#

!paste

magic cloudBOT
#
Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.

faint finch
#

thanks didn't knew

modern sierra
#

np

faint finch
#

here

#

i had this problem

#

please help

icy falcon
#

You're on linux?

faint finch
#

ys Pop os

#

Well i recently switch so don't know much

icy falcon
#

All good

#

Are all of your audio drivers up to date?

faint finch
#

ys

#

recently did some updates

#

and i even tried mic test online it worked

icy falcon
#

Okay, after some googling, it seems you need to run sudo nano /usr/share/alsa/alsa.conf and comment out cards.pcm.{device} where {device} is the unknown devices listed

faint finch
#

okay lets try

#

there are many with cards.pcm.{device}

icy falcon
#

look at the ones in the error message

#

cards.pcm.rear
cards.pcm.center_lfe
cards.pcm.side

faint finch
#

got it

#

okay i will find it

#

done

icy falcon
#

run the code again

faint finch
#

wait

icy falcon
#

what

faint finch
#

Error

icy falcon
#

aplay -l

faint finch
icy falcon
#

Which audio device do you use?

#

Actually, you should just be able to, in that same file, change defaults.ctl.card to 1, and defaults.pcm.card also to 1

faint finch
#

done

icy falcon
#

try again

faint finch
#

more error

icy falcon
#

that seems significantly worse

faint finch
#

yeah

icy falcon
#

change it back

faint finch
#

already done

icy falcon
#

try using .recognize() instead of .recongize_google()

faint finch
#

okay

#

no change

#

still error

icy falcon
#

run jack_control start in a terminal?

faint finch
#

there is no jack_control

icy falcon
#

i am copying things down from a google search here, try speaker-test -c2 -Dplughw:3

faint finch
#

speaker-test 1.2.8

Playback device is plughw:3
Stream parameters are 48000Hz, S16_LE, 2 channels
Using 16 octaves of pink noise
ALSA lib confmisc.c:165:(snd_config_get_card) Cannot get card index for 3
Playback open error: -2,No such file or directory
icy falcon
#

pip3 install sounddevice and then in your code import sounddevice

#

also, what microphone are you using?

faint finch
#

which microphone, if you are to device i am using my laptop built in microphone and specificly:

card 1: sofhdadsp [sof-hda-dsp], device 0: HDA Analog (*) []
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: sofhdadsp [sof-hda-dsp], device 1: HDA Digital (*) []
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: sofhdadsp [sof-hda-dsp], device 3: HDMI1 (*) []
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: sofhdadsp [sof-hda-dsp], device 4: HDMI2 (*) []
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: sofhdadsp [sof-hda-dsp], device 5: HDMI3 (*) []
  Subdevices: 1/1
  Subdevice #0: subdevice #0
faint finch
#

how to use it

#

sorry i don't know about this lib

#

i have installed it

icy falcon
#

just import it, apparently that helps

faint finch
#

no there is no error but nothing its recording nothing

icy falcon
#

is your input device set as your laptop mic?

faint finch
#

yeah then how i can test my mic online i can even listen my voice outside the code but there its not working

#

this is my mic which is working

#

but i noticed a problem when i use like any voice

#

there are two one is this and anothere one is with headset but that doesn't work and interesting thing is when i use google mic it use with headset one

#

i have to set it to this one

#

then only it worked

icy falcon
#

can you print pyaudio.get_device_count()

faint finch
#

okay

#

its saying there is nothing like .get_device_count()

icy falcon
#

did you import pyaudio?

faint finch
#

yes

#
import pyaudio
print(pyaudio.get_device_count())
icy falcon
#

print(pyaudio.PyAudio().get_device_count())

faint finch
#
Traceback (most recent call last):
  File "/home/pradeep/Code/Project/Iris/core/test.py", line 2, in <module>
    print(pyaudio.get_device_count())
faint finch
icy falcon
#
import speech_recognition as sr

for mic in sr.Microphone.list_microphone_names():
    print(mic)```
faint finch
icy falcon
#

replace Microphone() with Microphone(15)

faint finch
#

okay

#
Listening...
python3: malloc.c:4302: _int_malloc: Assertion `(unsigned long) (size) >= (unsigned long) (nb)' failed.
icy falcon
#

How much RAM do you have?

faint finch
#

16

faint finch
faint finch
icy falcon
#

Your speech code

icy falcon
#

can you run htop

faint finch
#

yeah sure

#

here i have also added btop

icy falcon
#

now run the code again, see what happens

faint finch
#

nope no error no recording

icy falcon
#

did you watch htop?

icy falcon
faint finch
#

okay

icy falcon
#

The error apparently means there's some misallocated memory, or just not enough

faint finch
#

hmm thats strange everything is fine

icy falcon
#
import speech_recognition as sr

def listen():
    """Recognizes speech and converts it to text."""
    recognizer = sr.Recognizer()
    with sr.Microphone() as source:
        print("Listening... Speak now.")
        try:
            # Listen with a pause of 3 seconds after silence
            audio = recognizer.listen(source, timeout=10, phrase_time_limit=3)
            print("Processing...")
            # Return the recognized text
            return recognizer.recognize_whisper(audio)
        except sr.UnknownValueError:
            return "Sorry, I couldn't understand that."
        except sr.RequestError:
            return "Sorry, there seems to be a problem with the recognition service."
        except sr.WaitTimeoutError:
            return "No speech detected within the time limit."

def main():
    """Main loop for the voice system."""
    print("Voice System Active. Speak to see the transcript. Say 'exit' to stop.")
    while True:
        transcript = listen().lower()
        if "exit" in transcript:
            print("Goodbye!")
            break
        print(f"Transcript: {transcript}")

if __name__ == "__main__":
    main()
``` Here's some code I ran on my machine that I know works, try it, see what happens
faint finch
#

it showing that it ran

#

here

icy falcon
#

make sure you run pip install SpeechRecognition[whisper-local]

faint finch
#

okay

#

error

icy falcon
#

whats the error now?

faint finch
icy falcon
#

and if you change sr.Microphone() to sr.Microphone(15) what happens

faint finch
#

malloc(): mismatching next->prev_size (unsorted)

icy falcon
#

What about sr.Microphone(0)

faint finch
#

Well good news I think I found the problem

#

It seems python can't access my mic directly

#

I had to adjust it

#

There are warning but there is also response

#

Thank you very much for the support

#

It's catching some audio but due network problem it couldn't access the Google api

icy falcon
#

You're welcome

faint finch
icy falcon
#

Yay!

faint finch
#

thanks to you

#

i will try to adjust those errors and warning

icy falcon
#

Alright, well have a good morning / evening / afternoon

faint finch
#

you too

#

that was a hell lot of brain storming

#

finnaly it end

#

what should i do with this post should i just let it be

icy falcon
#

I believe you do .close

magic cloudBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, 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.

#

๐Ÿ”’ Need help with speech recognition