Archive
HowTo: make raw_input & input work the same in both Python 2 and 3
Was just trying to make a Python 2 script work in Python 3 and at first it seemed I just needed a small change to add missing parentheses to the argument of a couple of print statements.
But then another issue came up, it wasn’t understanding the command raw_input(somePrompt) that was occuring at various places in that file to input text from the console.
Various solutions were proposed at
https://stackoverflow.com/questions/954834/how-do-i-use-raw-input-in-python-3/62825723
but I think I came up with a cleaner looking solution that works in both Python2 and Python3, that should allow one to use either raw_input or input in both Python2 and Python3 with the semantics of Python2’s raw_input (aka the semantics of Python3’s input).
# raw_input isn't defined in Python3.x, whereas input wasn't behaving
# like raw_input in Python 2.x. This should make both input and raw_input
# work in Python 2.x/3.x like the raw_input from Python 2.x
try: input = raw_input
except NameError: raw_input = input
In practice this came up from ideas at other answers on that SO thread. It tries to define input as raw_input which should fail in Python3.x since raw_input is undefined. In that case it will catch a NameError exception and do the reverse, aka define raw_input as input. However in Python2 the first command should execute fine, overriding the insecure input of Python2.x to work the same as raw_input (not trying to interpret input strings that is). Actually that is what Python 3.x input does.
Wonder why they didn’t declare it like that in the first place though, breaking compilation of Python2 programs. After all semantically only Python2 programs that were using the old insecure input would have an issue, not those that were using raw_input which is the semantics Python3 promotes with its newer input.
Managed .NET Speech API links
(this is my answer at http://stackoverflow.com/questions/14771474/voice-recognition-in-windows)
I’m looking into adding speech recognition to my fork of Hotspotizer Kinect-based app (http://github.com/birbilis/hotspotizer)
After some search I see you can’t markup the actionable UI elements with related speech commands in order to simulate user actions on them as one would expect if Speech input was integrated in WPF. I’m thinking of making a XAML markup extension to do that, unless someone can point to pre-existing work on this that I could reuse…
The following links should be useful:
http://www.wpf-tutorial.com/audio-video/speech-recognition-making-wpf-listen/
http://www.c-sharpcorner.com/uploadfile/mahesh/programming-speech-in-wpf-speech-recognition/
https://msdn.microsoft.com/en-us/library/hh855387.aspx (make use of Kinect mic array audio input)
http://kin-educate.blogspot.gr/2012/06/speech-recognition-for-kinect-easy-way.html
https://channel9.msdn.com/Series/KinectQuickstart/Audio-Fundamentals
https://www.microsoft.com/en-us/download/details.aspx?id=27225
https://www.microsoft.com/en-us/download/details.aspx?id=27226
http://www.redmondpie.com/speech-recognition-in-a-c-wpf-application/
http://www.codeproject.com/Articles/55383/A-WPF-Voice-Commanded-Database-Management-Applicat
http://www.codeproject.com/Articles/483347/Speech-recognition-speech-to-text-text-to-speech-a
http://www.c-sharpcorner.com/uploadfile/nipuntomar/speech-to-text-in-wpf/
http://www.w3.org/TR/speech-grammar/
https://msdn.microsoft.com/en-us/library/hh361625(v=office.14).aspx
Kinect for Xbox 360 and Kinect for Windows (KfW) v1 specs
1) 3D Depth sensor (IR Emitter + IR Camera / Depth Sensor)
2) RGB camera (Color Sensor)
3) Microphone array
4) Tilt motor (for detecting floor and players in the playspace)
Kinect | Specifications |
Viewing angle | Field of View (FoV): 43° vertical x 57° horizontal |
Vertical tilt range | ±27° |
Frame rate (depth and color stream) | 30 frames per second (FPS) |
Audio format | 16-kHz, 24-bit mono pulse code modulation (PCM) |
Audio input characteristics | 4-microphone array 24-bit analog-to-digital converter (ADC) onboard signal processing (including acoustic echo cancellation & noise suppression) |
Accelerometer characteristics | 2G/4G/8G accelerometer configured for 2G range 1° accuracy detail limit (can help detect when the sensor is in an unusual orientation) |
Sources:
https://en.wikipedia.org/wiki/Kinect
https://support.xbox.com/en-US/xbox-360/kinect/kinect-sensor-components