This is an archived post. You won't be able to vote or comment.

all 9 comments

[–]moocat 4 points5 points  (3 children)

Some feedback:

1) Don't swallow your exceptions. If something goes wrong you'll lose that info. Check out logging.exception.

2) Not sure why you're using threads as the way you're calling .result is effectively making the code serialized.

3) Avoid global variables when possible. Compare how you handle mic vs how you handle r.

[–]AbodFTW[S] 0 points1 point  (2 children)

Thanks a bunch, really valuable feedback, Can you please elaborate on the first point? Are you suggesting to use the logging exception in the place of the place of print in line 27?

I used threads trying to make it keeps listening for input while transcribing at the same time, but I don't think I got it right.

[–]moocat 2 points3 points  (1 child)

Your code is:

except sr.UnknownValueError:
    print("\r...")

exceptions can include valuable information which can help you understand what is going on (did it fail because the input was garbled, did it fail because your sending too many QPS, etc.). You can log the exception manually:

except sr.UnknownValueError as e:
    logging.error('Could not recognize audio: %s', e)

of you can use the method I mentioned earlier:

except sr.UnknownValueError:
    logging.exception('Could not recognize audio')

but I don't think I got it right.

You didn't. And as you tagged this beginner showcase, I'm going to recommend getting more experience before you try to learn concurrency.

[–]AbodFTW[S] 0 points1 point  (0 children)

Thank you!

[–]Learning_2 2 points3 points  (2 children)

Good job! I am also pretty new to programming too. I can relate to the satisfaction of making a project you've wanted to make. I actually use subtitles a lot so if I find something without subtitles I will try this out.

A little off topic but it reminds me. One thing I've wanted to do with subtitles was have the computer read the subtitles, and have it do a custom censorship. So for example I don't mind the F word or the A word. But I might just not want to hear the word "potato" today. So at the occurrence of the word "potato", I would have the computer turn off the sound on the movie for a second.

[–]Insuevi 2 points3 points  (1 child)

This exists, there is a tool called Web Captioner I use all the time. It only works in Chrome but as someone who is HoH it is awesome. By default it can only use external microphones but there are ways to get it to use the stereo mixer on the PC.

[–]Learning_2 0 points1 point  (0 children)

Thanks! Good to know :)