Wednesday, February 19, 2020

MatPlotLib With Live Data

If you are doing any charting with python, then you have probably used the matplotlib library. This library is full of features for creating attractive charts of your python-based data.

That's all well and good, but there's something else: You can chart live data with matplotlib! That's right--you can actually create python charts that update in real time. Actually, it is more of a "polling" system in which you create a chart animation function that will be called on a specified interval (1 second, 5 seconds, etc.). The effect is pretty sweet.

The code I'm playing around with for real-time python charts is in my Misc-python public GitHub repo (along with a bunch of other python code):
https://github.com/mdhatmaker/Misc-python/tree/master/Plot/matplotlib


You'll need to run live_data_plot.py and live_data_gen.py at the same time (one plots the data generated by the other). And make sure you run these from the same directory so the "live_data.csv" file can be located by both.

Final Note


If you are doing any python programming, make sure to check out Corey Schafer's YouTube channel. He is doing some really cool tutorials, especially for python and a variety of python libraries. I have used his channel to brush up on more specialized aspects of the python language, matplotlib, numpy, Flask, and a variety of other topics. Highly recommended.


Tuesday, February 18, 2020

Flask Is Slick

For a recent interview, I put together a bunch of python code. Some of it demonstrated simple OOP concepts. Some of it detailed Threading, Multiprocessing, and Subprocesses. Some banged on Pandas to create a decent chart of annual stock prices. Some of it used Quandl to retrieve historical data. Some of it used a REST API to download crude oil reports.

But by far, the coolest demo used Flask to rough-in code for a website.

Flask allows you to use Python (and some unique "template" syntax) to create good-looking websites in record time.

If you'd like to see for yourself, check out the "bp_interview/Flask_Blog" folder in my Misc-python public GitHub repo:
https://github.com/mdhatmaker/Misc-python/tree/master/bp_interview

It's not complete: I still need to flesh out the database code (using SQLite for development) and tighten up the security. But it's pretty damn cool. And it was so, so quick to build!

Friday, February 7, 2020

Beautiful Music With MIDI

Introduction


I'm a sucker for retro games (especially retro arcade games like those available via MAME). In particular, I like that old-school arcade theme music. Fortunately, there is a ton of this old-school arcade music on various websites. Unfortunately, a lot of this music is in the MIDI format.

MIDI


The Musical Instrument Digital Interface (or "MIDI") is a "technical standard for a communications protocol." But for our purposes, we are interested only in its ability to represent music in very small files (compared to MP3, WAV, etc.).

Playing Music With C#


I decided to see how difficult it would be to play MIDI music via C#. Short answer: It's not too bad!

I started with an article titled Making Music with MIDI and C#. From this article, I created some sample C# code that you can find on my "Misc-csharp" public GitHub repo in the "MidiSample" folder:
https://github.com/mdhatmaker/Misc-csharp

Playing Music With Python


Starting with an article titled Embed and Play Midi Music in your Code (Python), I created sample python code that you can find on my "Misc-python" public GitHub repo in the "Audio" folder:
https://github.com/mdhatmaker/Misc-python

I also added some sample ".mid" files to the "data/midi" folder.

Conclusion


Playing MIDI music from C# is pretty simple.

I'd like to add to the MidiApp project the ability download ".mid" files directly from the Video Game Music Archive website.


Thursday, February 6, 2020

UI Design With Qt

Telegram App


I came up through the ranks as a developer of desktop applications, so my experience in UI design has predominantly utilized desktop frameworks like Windows Forms, WPF, etc. I have since spent a good bit of time with web-based interfaces, but I still find some things work better as desktop apps.

Telegram, for example, is an excellent messaging app--and it has a desktop UI. There are versions for Windows, Mac, and Linux, and all versions look good and feel snappy. This begs the question: Is there a good cross-platform UI framework?

Qt Framework


One of the best cross-platform UI frameworks is Qt (currently version 5 referred to as "Qt5"). The python-specific version of this is "PyQt5".

To see my sample PyQt5 code, check out the "Qt" folder in my public "Misc-python" GitHub repo:
https://github.com/mdhatmaker/Misc-python

Conclusion


If you are looking for a good cross-platform framework for desktop UI design, check out Qt5 (and PyQt5 for python-specific work).

Updates:

Keep an eye on this space for coverage of the following topics:




Predict-It Python API

The PredictIt website provides a variety of non-standard betting markets (politics, world events, etc.). Utilizing PredictIt's public REST API, I have uploaded an initial version of python code that retrieves various Market and Contract data.

To try this code, check out my public "Misc-python" GitHub repository:
https://github.com/mdhatmaker/Misc-python

The PredictIt python code is in the "/Apis/predict-it" folder within this repository.

If you'd like to see the REST API description that I used to create this code, check out the following link:
https://predictit.freshdesk.com/support/solutions/articles/12000001878-does-predictit-make-market-data-available-via-an-api-

I have started looking at more advanced sample code that implements additional functionality (such as actual trading of contracts). As I make progress, I'll post updates here.




Monday, February 3, 2020

Coding Interview Prep

Do you have some coding interviews coming up? Well lucky for you, I did the work of collecting coding questions from a bunch of different websites:
https://github.com/mdhatmaker/coding-interview-prep

Initially, I pulled this together for a Google interview, but I've added a lot since then. I need to add my additional (handwritten) notes along with my recommended reading list (mostly Google-centric books).

I'll post updates here when I add to this Coding Interview Prep repo...

Updates:


Feb 3, 2020 - initial code introduction


YouTube Downloader

Sometimes you just want to download your favorite YouTube videos. Given YouTube's continuous march toward censorship, this is never a bad idea, but there are a lot of other reasons to want access to the vast library of YouTube videos.

Step 1: Download YouTube Video/Audio


I recently started work on a little project that will download YouTube videos in order to grab the audio track and run it through Machine Learning algorithms. Step one, of course, is to download the video to your local storage. I originally thought Python would be the best way to proceed with this step, but it seems C# provides the most functionality in terms of downloading YouTube videos.

Check out this GitHub repository for a variety of sample C# code:
https://github.com/mdhatmaker/YouTubeDownload

This code does some video downloading (YouTube only), and it also has some simplistic ability to grab just the audio track and save it to an MP3 file.

Here's where I started when developing this code:
https://stackoverflow.com/questions/39877884/c-sharp-download-the-sound-of-a-youtube-video

Step 2: Convert Speech to Text


Once we have the audio track(s) saved locally, we can start converting the speech to text.

Within my miscellaneous Python code repo, check out the "voice_to_speech_demo.py" file:
https://github.com/mdhatmaker/Misc-python

The python SpeechRecognition library seems like a good place to start:
https://www.datasciencewiki.com/2019/12/speechvoiceaudio-to-text-conversion.html

My first attempt uses the Google Cloud Speech API to do the audio-to-text conversion. It seems I have to jump through some hoops to get the Google API to convert more than about 60-second clips, but it does work (and the accuracy seems quite good).

The SpeechRecognition python library supports a variety of speech-recognition APIs.

Below are the Speech recognition engine/API support as of now:
  1. CMU Sphinx (works offline)
  2. Google Speech Recognition
  3. Google Cloud Speech API
  4. Wit.ai
  5. Microsoft Bing Voice Recognition
  6. Houndify API
  7. IBM Speech to Text
  8. Snowboy Hotword Detection (works offline)
Obviously, I need to address the issue of processing longer audio clips. Also, it would be cool to try an API that does the speech recognition locally (rather than in the cloud). My plan is to try the following engines next and compare the results with Google Cloud Speech API: Google Speech Recognition, Microsoft Bing Voice Recognition, and IBM Speech to Text.

Step 3: Use Machine Learning Prediction to Simulate Speech Patterns


Once I have the "textified" version of audio from a speaker in some YouTube videos, I can start the process of doing "next-word prediction" to attempt to simulate the speaker's patterns. I'll write follow-up posts as I work through this step...

Conclusion


The goal of this nerdy little project is to pull a speaker's audio from his/her YouTube videos then simulate that person's speech patterns. If want to add some extra "coolness," I will evaluate some text-to-speech libraries to convert the simulated speech back to audio.

Sounds pretty fun. We'll see.