Using Tkinter for a subtitle application, Python - python

I am trying to create an automatic subtitle writer program to be used for online presentations using Python. Basically, the program will listen to your microphone, and display the words you've said on your screen. This is what I have done so far:
import speech_recognition as sr
r = sr.Recognizer()
count = 1
while count <= 5:
with sr.Microphone() as source:
print(" ")
audio = r.listen(source)
try:
text = r.recognize_google(audio)
print("{}".format(text))
except:
print("")
Now I know it's not much, but I am trying my best as I'm very, very new to programming. Anyways, I found out an hour ago that Tkinter is a good tool to use for this project, especially when it comes to having the window (where the subtitles are displayed) always on top of your screen. However, I am failing to understand how to properly use it in my case.
So my question is, what should I do to incorporate Tkinter in to my project?

Related

Stuck with catpcha solving in python

We are writing a very simple code for a game which automates an enhancing process (it's our own server so it's just for the fun of it) during this process you occasionally get a captcha which you have to solve in order to continue enhancing. We are stuck up on how we could solve the captchas and this is where we need your help. The code is written in python and is very simple. The captcha is also very simple it's only 3 numbers. (can't be anything else other than numbers from 0-9) Here is how the captcha window looks like: [https://i.stack.imgur.com/27mAK.png]
The code looks like this:
import pyautogui
import time
import keyboard
while True:
opt = pyautogui.locateOnScreen('asd.png', confidence=.95) #looks for a good enchant
forgat = pyautogui.locateOnScreen('forgatas.png') #locates the button to press for enhancing
stop = keyboard.is_pressed("shift") #stops the loop with shift
if opt:
print('Done')
break
if stop:
print('Stopped')
break
else:
pyautogui.click(forgat)
time.sleep(0.2)
Did some testing with pytesseract:
from cv2 import cv2
import pytesseract
import pyautogui
pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe'
img = cv2.imread('ak.png')
text = pytesseract.image_to_string(img)
print(text)
It successfully converts the img to text but we can't figure out how to copy the text into the text-box in game. Copying the ingame text is not an option.
Would also like to ask you to give suggestions regarding speeding up the process while the locateOnScreen function is still able to keep up (don't want the code to skip over a good enchant for going too fast) and maybe using something else instead of time.sleep because it heavily taxes the system. Sorry if the code is messy we are still very much beginners and we never learned python before. Any help would be greatly appricated! Looking forward to any suggestion!
I suggest you to try this library I've found some time ago. If you have a set of labelled captchas that service would fit you. Take a look: https://github.com/punkerpunker/captcha_solver
In README there is a section "Train model on external data" that you might be interested in.

Converting speech to text in real time using 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 :)

Using a Raspberry pi, mic works perfectly fine for everything, except for code (r.listen(source))

I'm working on a speech to morse code Group Project. The problem is that the raspberry pi has a problem of using the USB mic in the listen() function of the program.
It works completely fine on laptops, but it doesn't on an RPi for some reason. The mics work completely fine everywhere else, using arecord -d, and testing on discord. I installed a majority of the stuff required using pip install: Pyaduio, speech recognition, and portaudio, at least all the stuff I needed for the laptops. I am using Python 2.7.13, and I've tried it on Python 3; same issue.
import speech_recognition as sr
r = sr.Recognizer()
with sr.Microphone() as source:
print("Speak Anything :")
audio = r.listen(source)
try:
text = r.recognize_google(audio)
print("You said : {}".format(text))
except:
print("Sorry could not recognize what you said")
The expected result is supposed to print what you said; however, what it would do is either get stuck on "Speak Anything:" or "Sorry could not recognize what you said."
I really need some help with this. Out of everything to do on this project, I've spent the most time on this, which seems to be something that is supposed to be easy.

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.

Displaying live scorecard on linux desktop

I have written a python script which displays all the live matches scores. I wish to display the score on my desktop rather than in terminal. I also wish to update the score card every 5 minutes or so.
Here is the python script:
import xml.etree.cElementTree as ET
import requests
tree = ET.fromstring(requests.get('http://www.cricbuzz.com/livecricketscore/home-score-matches.xml').text)
for elem in tree.iter('match'):
state = elem.find('state').text
footer = elem.find('footer').text
header = elem.find('header').text
print state,header,footer
xml file used for parsing
How can I achieve the above?
You will need to build a GUI for this. There are a lot of libraries that should help. A couple as example - PyQT4, Tkinter, easygui etc.
You don't need any fancy GUI stuff like Vikas Neha Suggested. All you need is pynotify library.
pynotify.init("TEST")
notice=pynotify.Notification("Your Score card",string_to_show)
notice.show()
This would Display your message onto the Bubble notification on your screen.

Categories

Resources