Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speech Transcription #1

Open
alanknguyen314 opened this issue May 10, 2023 · 0 comments
Open

Speech Transcription #1

alanknguyen314 opened this issue May 10, 2023 · 0 comments

Comments

@alanknguyen314
Copy link
Owner

alanknguyen314 commented May 10, 2023

{
"cells": [
{
"cell_type": "markdown",
"id": "ff457600-78ed-462f-935d-0870b6734680",
"metadata": {},
"source": [
"## 1. Speech to Text using Python🎤"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "90d4a41f-e0ae-4962-96aa-2a339fea46be",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/studio-lab-user/.conda/envs/default/lib/python3.9/site-packages/requests/init.py:102: RequestsDependencyWarning: urllib3 (1.26.13) or chardet (5.0.0)/charset_normalizer (2.0.12) doesn't match a supported version!\n",
" warnings.warn("urllib3 ({}) or chardet ({})/charset_normalizer ({}) doesn't match a supported "\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"transcript_id = '6km8tavygz-0570-4a28-b98a-7e066f83fc05'\n",
"Getting the transcription result ....\n",
"Getting the transcription result ....\n",
"Getting the transcription result ....\n",
"Getting the transcription result ....\n",
"('The following is the short story Innocence by Honoree Debalzac, presented by '\n",
" 'listen to Genius.com, narrated by Mel Foster by the double crest of my foul '\n",
" "and by the rose lining of my sweetheart's slipper, by all the horns of well "\n",
" 'beloved cuckolds, and by the virtue of their blessed wives. The finest work '\n",
" 'of man is neither poetry, nor painted pictures, nor music, nor castles, nor '\n",
" 'statues, be they carved never so well, nor rowing, nor sailing galleys. But '\n",
" 'children, understand me, children up to the age of ten years, for after that '\n",
" 'they become men or women, and cutting their wisdom teeth are not worth what '\n",
" 'they cost. The worst are the best. Watch them playing prettily and '\n",
" 'innocently with slippers. Above all, cancellated ones with the household '\n",
" 'utensils, leaving that which displeases them, crying after that which '\n",
" 'pleases them, munching the sweets and confectionery in the house, nibbling '\n",
" 'at the stores, and always laughing as soon as their teeth are cut. And you '\n",
" 'will agree with me that they a')\n"
]
}
],
"source": [
"import requests\n",
"from pprint import pprint\n",
"from time import sleep\n",
"from config import ASSEMBLY_AI_TOKEN as api_key\n",
"\n",
"audio_url = 'https://listentogenius.com/recordings4/Innocence.mp3'\n",
"endpoint = "https://api.assemblyai.com/v2/transcript"\n",
"\n",
"headers = {\n",
" 'authorization': api_key, \n",
" 'content-type': 'application/json'\n",
"}\n",
"\n",
"body = { 'audio_url': audio_url}\n",
"\n",
"# 1. Submitting Files for Transcription\n",
"\n",
"res = requests.post(endpoint, json=body, headers=headers)\n",
"transcript_id = res.json().get('id')\n",
"print(f'{transcript_id = }')\n",
"\n",
"# 2. Getting the Transcription Result\n",
"\n",
"endpoint_full = f"https://api.assemblyai.com/v2/transcript/{transcript_id}"\n",
"status = 'processing'\n",
"while status != 'completed':\n",
" print('Getting the transcription result ....')\n",
" sleep(5)\n",
" res_text = requests.get(endpoint_full, headers=headers)\n",
" status = res_text.json().get('status')\n",
"data = res_text.json().get('text')\n",
"pprint(data[:1000])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2d368b82-c11d-4ffa-a6cc-7de1285d6d72",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "default:Python",
"language": "python",
"name": "conda-env-default-py"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.12"
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"state": {},
"version_major": 2,
"version_minor": 0
}
}
},
"nbformat": 4,
"nbformat_minor": 5
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant