{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import json\n", "import requests\n", "import os\n", "API_TOKEN = os.environ[\"API_TOKEN\"]\n", "headers = {\"Authorization\": f\"Bearer {API_TOKEN}\"}\n", "API_URL = \"https://api-inference.huggingface.co/models/facebook/wav2vec2-base-960h\"\n", "\n", "def query(filename):\n", " with open(filename, \"rb\") as f:\n", " data = f.read()\n", " response = requests.request(\"POST\", API_URL, headers=headers, data=data)\n", " return json.loads(response.content.decode(\"utf-8\"))\n", "\n", "data = query(\"test.wav\")\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "data" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from transformers import pipeline\n", "\n", "with open(\"test.wav\", \"rb\") as f:\n", " data = f.read()\n", "\n", "pipe = pipeline(\"automatic-speech-recognition\", \"facebook/wav2vec2-base-960h\")\n", "pipe(\"test.wav\")\n", "# {'text': \"GOING ALONG SLUSHY COUNTRY ROADS AND SPEAKING TO DAMP AUDIENCES IN DRAUGHTY SCHOOL ROOMS DAY AFTER DAY FOR A FORTNIGHT HE'LL HAVE TO PUT IN AN APPEARANCE AT SOME PLACE OF WORSHIP ON SUNDAY MORNING AND HE CAN COME TO US IMMEDIATELY AFTERWARDS\"}\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3.8.13 64-bit", "language": "python", "name": "python3" }, "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.8.13" }, "orig_nbformat": 4, "vscode": { "interpreter": { "hash": "949777d72b0d2535278d3dc13498b2535136f6dfe0678499012e853ee9abcab1" } } }, "nbformat": 4, "nbformat_minor": 2 }