{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Creating the NENA Speech Dataset" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Download validated examples from Pocketbase" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from pocketbase import PocketBase\n", "\n", "pb = PocketBase('https://pocketbase.nenadb.dev/')\n", "\n", "dialects = pb.collection(\"dialects\").get_full_list(query_params={\n", " \"sort\": \"name\",\n", "})\n", "\n", "examples = pb.collection(\"examples\").get_full_list(query_params={\n", " \"expand\": \"dialect\",\n", " \"filter\": \"validated=true\",\n", "})" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create shards" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from pydub import AudioSegment\n", "import requests\n", "import tempfile\n", "\n", "test_split = 0.10\n", "dev_split = 0.10\n", "\n", "for i, example in enumerate(examples):\n", " prog = i / len(examples)\n", " \n", " if prog < test_split:\n", " split = 'test'\n", " elif prog < dev_split + test_split:\n", " split = 'dev'\n", " else:\n", " split = 'train'\n", "\n", " audio_url = pb.get_file_url(example, example.speech, {})\n", " response = requests.get(audio_url)\n", "\n", " with tempfile.NamedTemporaryFile() as f:\n", " f.write(response.content)\n", " f.flush()\n", " audio = AudioSegment.from_file(f.name)\n", "\n", " audio = audio.set_frame_rate(48000)\n", " audio.export(f\"nena_speech_{example.id}.mp3\", format=\"mp3\")\n", "\n", " break" ] } ], "metadata": { "kernelspec": { "display_name": "venv", "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.11.5" }, "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2 }