Converting speech to text in real time using Python - python

I'm currently trying to create a program that will print what is being said through a microphone input into console as it is being said, rather in just one big block after the user is finished saying whatever they want to say. How would I extend the SpeechRecognition/PyAudio Modules in order to achieve this. I'm thinking it may involve being able to detect when someone has finished saying a word and then looping back around to the voice detection, but I wouldnt be sure how to implement that.
This is just the basic example I'm going off of in order to print the text after the user is finished speaking:
microphone = sr.Microphone(device_index=0)
r = sr.Recognizer()
with microphone as source:
audio = r.listen(source)
print(r.recognize_google(audio))
Thanks :)

Related

voice assistant in python has the following problem

I am making a python voice assistant as I pass a command like search Wikipedia and read it, if I want it to stop it wont stop until it completes all the matter present in it can anyone help me with this. I don't know what to do

Is there a way to imitate sound input with python?

I wanted to make a program that would pass some sound data to the system's microphone, imitating person's speech. Originally I wanted it to "talk" in a discord voice chat to other people, but I couldn't find any way to do so.
I tried libraries like SoundCard and PyAudio, but they seem to only have functions to either get the mic input from the user, or to output sound via speakers. However, I want it to simulate microphone input.
So, is there any way to do this with python (or any other language)?
Thanks in advance.

Python speech recognition very slow

I am currently developing a smart assistant program (basically it is just listening to what the user says and based on that does something with the code). It was working fine up until today, when I switched to my laptop. The program does not print out any errors, but it also doesn't print out what I said. I'm using the Python Speech Recognition library version 3.8.1. Does anybody know of an alternative for this library? If yes, please try to explain how I would use it 'on the fly' (without first recording the file and then sending it to the server, more like real-time speech).
EDIT: I forgot to say it in the post, I'm using Python 3.
EDIT: Here's the code:
#!/usr/bin/env python3
import speech_recognition as sr
global x
def speech():
try:
with sr.Microphone() as source:
global x
r = sr.Recognizer()
audio = r.listen(source)
x = r.recognize_google(audio)
except sr.UnknownValueError:
print("No clue what you said, listening again... \n")
speech()
if __name__ == '__main__':
print('Listening and printing what I heard: \n')
speech()
print(x)
I found that the problem was in the laptop's microphone. The speech recognition worked fine after I plugged in my Blue Snowball. I forced the program to use the Blue Snowball by going into pavucontrol and selecting the Blue Snowball under the recording tab.
Another reason could be that your mic levels are either too high or too low,
in both the cases the speech_recognition would get either too less audio or too much audio to work with. Take a look at that in your system settings. It helped me, hope it helps you.

Python audio Mpylayer with mplayer

Hi all brand new to Python, I am working on a script that plays some audio for me via GPIO triggers. Script works great, only thing is I want the audio to loop.
I am using a Python plugin called Mpylayer.
In a simplified version of what I have, this is where I am stuck,
Mp1 = mpylayer.MPlayerControl()
Mp1.loadfile('/path/to/audio.wav')
Mp1.loop = 1
And then in a separate function/GPIO trigger I have,
Mp1.quit()
Ideally the audio would loop forever, till the quit trigger. Again, that part works great, it's just the getting it to loop part. The docs for the plugin seem to say there is a way to do it, but if hit a roadblock.
Thanks for any help!
--Daniel
Try:
Mp1 = mpylayer.MPlayerControl()
Mp1.loadfile('/path/to/audio.wav')
Mp1.loop = 0
It will loop for ever if you give the value 0.

Can't get winsound.Beep to work

I am trying to make some Beep noises with the winsound.Beep command. However when I am using winsound.Beep(500, 500) I do not hear anything. With winsound.MessageBeep and winsound.PlaySound however, I DO get to play sounds. Any ideas what I should do?
What I am trying to do: I want to write a little practicing program for training intervals: the computer sounds a first tone, then a second tone and you will have to guess what the tone interval is. For this I need pitched tones, tones for which I can set the frequency. I want to keep it as simple as possible, any pitched sound will do. I do not want to have to collect a set of .wav files or whatever. I want to make use of a tone generator which I think is available on most soundcards. winsound.Beep seems like something that can do this trick, but any other suggestions are welcome.
I had the exact same problem. winsound.Beep used to work just fine and then it suddenly stopped working (or that's what I thought). The problem was that someone (or some update) had turned off the System sounds, which prevented windows from playing the Beep sound, either manually or through my program. Try right clicking on the Speaker symbol, Open volume mixer and check whether System sounds is off or minimum volume.
I hope that helps!
Are you sure that your computer has a beep? A lot of recent computer remove the beep because it was annoying and most computer today have soundcard to play wav sound instead (the other sound that you are able to play).
You can also check to validate if it's activated on this page
IMO, I think that using the beep for other things than debugging is not a good idea.
EDIT
Mayby you can try this code to create a sound using a base wav with synth algorythm

Categories

Resources