{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d3b8e482-a429-4c09-9d8b-f5d43e721ea5",
   "metadata": {},
   "outputs": [],
   "source": [
    "import torch\n",
    "import whisper_timestamped as whisper\n",
    "import sys, os\n",
    "import json"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "151eef93-7fb4-4199-b2e0-9183bdcc455a",
   "metadata": {},
   "outputs": [],
   "source": [
    "myhome = os.path.expanduser(\"~\")\n",
    "root_folder = myhome + \"/special\"\n",
    "output_folder = root_folder"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c4f6b18f-6552-441e-9cbc-10ef35d022f2",
   "metadata": {},
   "outputs": [],
   "source": [
    "mydevice = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\n",
    "print(mydevice)\n",
    "model = whisper.load_model(\"large-v3\", device=mydevice)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "681caa03-bc61-4482-bc25-ac3ea8a36596",
   "metadata": {},
   "outputs": [],
   "source": [
    "myaudio = \"animals.wav\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7260044b-de41-4091-8b65-274a7dc2cfe6",
   "metadata": {},
   "outputs": [],
   "source": [
    "audio = whisper.load_audio(myaudio)\n",
    "result = whisper.transcribe(model, audio, language=\"en\", vad=True)                         "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1e0190db-3fc8-4769-b002-e3f9e467cdba",
   "metadata": {},
   "outputs": [],
   "source": [
    "filename_no_ext = os.path.splitext(myaudio)[0]\n",
    "newfile=filename_no_ext + '.json'\n",
    "print(newfile)\n",
    "with open(newfile, 'w') as f:\n",
    "    json.dump(result, f, indent=2)      "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.12.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
