Skip to content

Instantly share code, notes, and snippets.

View G10DRAS's full-sized avatar

G10DRAS G10DRAS

View GitHub Profile
@G10DRAS
G10DRAS / CurrencyRateConverter.py
Last active June 8, 2018 04:45
Currency Rate Converter [working]
import urllib2
import json
curr_from = "JPY"
curr_to = "INR"
curr_input = 1
curr_pair = curr_from + "_" + curr_to
api_url = "https://free.currencyconverterapi.com/api/v5/convert?q={0}&compact=ultra".format(curr_pair)
jsonurl = urllib2.urlopen(api_url)
rate_json = json.loads(jsonurl.read())
rate = curr_input * float(rate_json[curr_pair])
@G10DRAS
G10DRAS / wifi_monitor.sh
Created April 5, 2017 01:27
WiFi Monitor - Restart WiFi
#!/bin/bash
##################################################################
#
# Purpose:
#
# Script checks to see if WiFi has a network IP and if not
# restart WiFi
#
# Uses a lock file which prevents the script from running more
# than one at a time. If lockfile is old, it removes it
@G10DRAS
G10DRAS / YAMLGui.py
Created April 5, 2017 01:25
YAML QT GUI
#!/usr/bin/env python2
# -*- coding: utf-8-*-
# Copyright 2016 g10dras.
__author__ = 'g10dras'
import sys
import yaml
from PyQt4 import QtGui, QtCore
@G10DRAS
G10DRAS / FindDeviceIndex.py
Last active April 5, 2017 01:26
Find ALSA Device Index
import pyaudio
po = pyaudio.PyAudio()
for index in range(po.get_device_count()):
desc = po.get_device_info_by_index(index)
print ("DEVICE: {0} \t INDEX: {1} \t RATE: {2}".format(desc["name"],index,int(desc["defaultSampleRate"])))
@G10DRAS
G10DRAS / alsaplugins
Last active April 5, 2017 01:31
Alsa Plugins
pcm.usb
{
type hw
card Device
}
pcm.!default
{
type asym
playback.pcm
{
@G10DRAS
G10DRAS / alsacommands
Last active September 29, 2016 00:28
ALSA Problem Solving on Jessie
lsusb
lsusb -v -d 1b3f:2007 | grep tSamFreq
cat /proc/asound/cards
cat /proc/asound/modules
cat ~/.asoundrc
cat /etc/asound.conf
alsamixer -c 0
alsamixer -c 1
@G10DRAS
G10DRAS / google-speech-recog.sh
Created September 29, 2016 00:00
Test Google Speech Private API
#!/bin/bash
hardware="plughw:0,0"
duration="4"
lang="en"
client="Mozilla/5.0"
apikey="XXxxXXxXxXxxXX_8XxxXXXXxxxxx_X8XXxxxxxX"
arecord -D $hardware -f S16_LE -t wav -d $duration -r 16000 | flac - -f --best --sample-rate 16000 -o /tmp/out.flac 1>/tmp/voice.log 2>/tmp/voice.log; curl -X POST --data-binary @/tmp/out.flac --user-agent 'Mozilla/5.0' --header 'Content-Type: audio/x-flac; rate=16000;' "https://www.google.com/speech-api/v2/recognize?output=json&lang=$lang&pfilter=2&maxresults=6&key=$apikey&client=$client" | sed -e 's/[{}]/''/g' | awk -F":" '{print $4}' | awk -F"," '{print $1}' | tr -d '\n'
@G10DRAS
G10DRAS / FindAlsaDevices.py
Created September 8, 2016 02:35
Find Alsa Devices
"""Extract alsa hardware device descriptions/ids from arecord/aplay"""
import subprocess, re, logging, json
log = logging.getLogger( __name__ )
CARD_MATCH = re.compile(r'card (?P<card>\d+)[:].*?[[](?P<description>.*?)[]], device (?P<device>\d+)[:].*?[[](?P<device_description>.*?)[]]' )
def get_inputs( ):
"""Get alsa inputs (relies on having arecord present)"""
output = subprocess.check_output( ['arecord','-l'] )
cards = [line for line in output.splitlines() if line.startswith( 'card ' )]
@G10DRAS
G10DRAS / PyAudioPocketSphinx.py
Last active September 8, 2016 02:33
PocketSphinx with PyAudio Recording
#!/usr/bin/env python
from pocketsphinx.pocketsphinx import *
from sphinxbase.sphinxbase import *
import os
import pyaudio
import wave
import audioop
from collections import deque
@G10DRAS
G10DRAS / sendText.py
Created August 11, 2016 07:56
Twilio Script
from twilio.rest import TwilioRestClient
accountSID = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
authToken = 'xxxxxxxxxxxxxxxxxxxxxxxx'
myTwilioNumber = '+xxxxxxxxxxxxxxxxxx'
myCellPhone = '+xxxxxxxxxxxx'
def text(message):
twilioCli = TwilioRestClient(accountSID, authToken)