Skip to content

Instantly share code, notes, and snippets.

View arnaldorusso's full-sized avatar

Arnaldo Russo arnaldorusso

View GitHub Profile
import cv2
cap = cv2.VideoCapture(0)
while True:
_, frame = cap.read()
hsvMin = (20,120,120)
hsvMax = (49,255,255)
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
@arnaldorusso
arnaldorusso / speech2text.py
Created August 19, 2017 21:06 — forked from baali/speech2text.py
A Python script to break audio into chunks of smaller audios and using Google API to get Speech to Text.
'''
A hack based on this http://mikepultz.com/2011/03/accessing-google-speech-api-chrome-11/. While with smaller voice samples google speech to text works really good, as length increases quality decreases. So here using audiolab and numPy we are breaking audio sample, in smaller chunks, and removing blank/empty spaces from audio signal and then pushing them to google for processing.
It takes wav file format as input but can be changed to other formats too.
'''
from scikits.audiolab import wavread, play, flacwrite
from numpy import average, array, hstack
import os
import sys
@arnaldorusso
arnaldorusso / midi2mp3
Created January 24, 2016 13:45 — forked from kroger/midi2mp3
Convert MIDI files to MP3 using fluidsynth. See
#!/usr/bin/env bash
SOUNDFONT=/Users/kroger/Dropbox/Sfonts/BOPLMEVF16.sf2
TMPDIR=/tmp
if [[ ! -f $SOUNDFONT ]]
then
echo "Couldn't find the soundfont: $SOUNDFONT"
exit 1
# When setuptools need to be upgraded
(venv) $ python -m pip install --upgrade --force setuptools
(venv) $ python -m pip install --upgrade --force pip
@arnaldorusso
arnaldorusso / Generate WAV from MIDI.md
Last active January 22, 2016 17:02 — forked from jiaaro/Generate WAV from MIDI.md
Generate a wave file from a MIDI file with Pydub

Simple example of rendering a midi file with Pydub

Basically, this takes a MIDI input file (I just googled and grabbed one of Maroon 5's "Animal" – I know, I know) and generates a WAV file.

NOTE: This is the slowest midi rendering program I have ever seen!

Dependencies:

@arnaldorusso
arnaldorusso / docx2md.md
Last active August 29, 2015 14:20 — forked from vdavez/docx2md.md

Converting a Word Document to Markdown in Two Moves

The Problem

A lot of important government documents are created and saved in Microsoft Word (*.docx). But Microsoft Word is a proprietary format, and it's not really useful for presenting documents on the web. So, I wanted to find a way to convert a .docx file into markdown.

The Solution

As it turns out, there are several open-source tools that allow for conversion between file types. Pandoc is one of them, and it's powerful. In fact, pandoc's website says "If you need to convert files from one markup format into another, pandoc is your swiss-army knife." But, although pandoc can convert from markdown into .docx, it doesn't work in the other direction.

@arnaldorusso
arnaldorusso / Plot_utilities
Created April 2, 2015 14:08
Cloned from jklymak/pythonlib
#!/usr/local/bin/python
# Filename: jmkfigure.py
# from matplotlib import rc
from pylab import *
def djmkfigure(width,vext):
"""
djmkfigure(width,vext):
width is column widths, and vext is fractional 10 page height.
@arnaldorusso
arnaldorusso / Pandas_shortcut_examples.py
Last active June 26, 2018 20:10 — forked from why-not/gist:4582705
Pandas simple examples
"""quick way to create a data frame to try things out"""
df = pd.DataFrame(np.random.randn(5, 4), columns=['a', 'b', 'c', 'd'])
df['A'] """ will bring out a col """ df.ix[0] """will bring out a row, #0 in this case"""
"""Given a dataframe df to filter by a series s:"""
df[df['col_name'].isin(s)]
"""to do the same filter on the index instead of arbitrary column"""
df.ix[s]

Stacked and Grouped Bar Plot

Oddly enough ggplot2 has no support for a stacked and grouped (position="dodge") bar plot. The seaborn python package, although excellent, also does not provide an alternative. However, I knew it was surely possible to make such a plot in regular matplotlib. Matplotlib, although sometimes clunky, gives you enough flexibility to precisely place plotting elements which is needed for a stacked and grouped bar plot.

Below is a working example of making a stacked and grouped bar plot.

import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np
@arnaldorusso
arnaldorusso / .vimrc
Last active August 29, 2015 14:15 — forked from cuducos/init.vim
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" NeoBundle "
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" install and init NeoBundle
if has('vim_starting')
set nocompatible
set runtimepath+=~/.vim/bundle/neobundle.vim/
endif