A union of curiosity and data science

Knowledgebase and brain dump of a database engineer


Google Translate API - Wav file speech recognition with python3


This api transcribes up to 1 min of audio to text. You'll need a google cloud account. 

https://cloud.google.com/translate/docs/

#!/usr/bin/env python3

import speech_recognition as sr
from os import path

audio = "K:\\random\\part4.wav"
r = sr.Recognizer() #recognizer object, we can use various services with this including  google, microsoft and ibm watson
with sr.AudioFile(audio) as source:
    audio = r.record(source)  # read the entire audio file

# Google Cloud Speech Recognition
Whisper = r"""<entire contents of json credentials from google>"""
try:
    ish =  r.recognize_google_cloud(audio, credentials_json=Whisper)
    print("Transcribed:...  " +ish)
#canwehassavedfile!
    file = open("K:\\random\\part4.txt","w")
    file.write(ish)
    file.close()
except sr.RequestError as e:
    print("Sorry, can't help you. ; {0}".format(e))
except sr.UnknownValueError:
    print("What was that?")

 

Find Python Path

from command line :

python c - "import sys, os; print(os.path.dirname(sys.executable))"



from python: 

import sys, os
os.path.dirname(sys.executable)



 

python --version

python -V

EC2 and Redshift - Set Password File - use Bash / PSQL / Select without interactive password

1. Install PSQL on the machine you plan on connecting to Redshfit with. 

I used an Amazon Linux AMI

Once connected through SSH run the following: 

> sudo yum update
> sudo yum install postgresql

 

Test that you can connect to your Redshift Server. 

> psql -h my-connection-string -p my-port# -U user -d mydb


you'll be promted for the pasword. Once this works, we can setup the PGPASSFILE.

2. Create the Password File.

$ touch ~/.pgpass
$ chmod 0600 ~/.pgpass

Use your favorite text editor to add the following line to the file.

hostname:port:database:username:password


You can find more information regarding this file here : https://www.postgresql.org/docs/9.2/static/libpq-pgpass.html


3. Create a shell script to test your auto authentication. <yourscript>.sh

#!/bin/sh
set PGPASSFILE=~/.pgpass
psql -h <host url> -p <port> -U <user> -d <db_name>  -c "Select 'Hello World' "
echo Done

Save this script on your ec2 instance. Run it.

$ sh <yourscript>.<ext>