{ "cells": [ { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "The autoreload extension is already loaded. To reload it, use:\n", " %reload_ext autoreload\n" ] } ], "source": [ "import sys\n", "sys.path.insert(0, '/home/ons21553/wspace/interview-transcripts/src')\n", "from common import *\n", "\n", "%load_ext autoreload\n", "%autoreload 2" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import io\n", "import os\n", "\n", "# Imports the Google Cloud client library\n", "from google.cloud import speech\n", "from google.cloud.speech import enums\n", "from google.cloud.speech import types" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "from common import *" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [], "source": [ "os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = from_root('dcm-iw-transcripts-db3f1fa338cc.json')" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [], "source": [ "# Instantiates a client\n", "client = speech.SpeechClient()" ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [], "source": [ "import recordings.harvard as hv\n", "r = hv.load_all()[0]" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [], "source": [ "with io.open(r.audio_fpath, 'rb') as audio_file:\n", " content = audio_file.read()\n", " audio = types.RecognitionAudio(content=content)" ] }, { "cell_type": "code", "execution_count": 31, "metadata": {}, "outputs": [], "source": [ "config = types.RecognitionConfig(\n", " encoding=enums.RecognitionConfig.AudioEncoding.LINEAR16,\n", " language_code='en-US')\n", "\n", "# Detects speech in the audio file\n", "response = client.recognize(config, audio)" ] }, { "cell_type": "code", "execution_count": 34, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
| \n", " | text | \n", "speaker | \n", "from | \n", "end | \n", "
|---|---|---|---|---|
| 0 | \n", "The small pup gnawed a hole in the sock. | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
| 1 | \n", "The fish twisted and turned on the bent hook. | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
| 2 | \n", "Press the pants and sew a button on the vest. | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
| 3 | \n", "The swan dive was far short of perfect. | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
| 4 | \n", "The beauty of the view stunned the young boy. | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
| 5 | \n", "Two blue fish swam in the tank. | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
| 6 | \n", "Her purse was full of useless trash. | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
| 7 | \n", "The colt reared and threw the tall rider. | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
| 8 | \n", "It snowed, rained, and hailed the same morning. | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
| 9 | \n", "Read verse out loud for pleasure. | \n", "NaN | \n", "NaN | \n", "NaN | \n", "