diff --git "a/data_example.ipynb" "b/data_example.ipynb" new file mode 100644--- /dev/null +++ "b/data_example.ipynb" @@ -0,0 +1,238 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd\n", + "from libris2s_dataset import Libris2sDataset" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " DE_audio \\\n", + "book_id \n", + "10 DE\\10.buchsederpandora_1501_librivox\\sentence_... \n", + "10 DE\\10.buchsederpandora_1501_librivox\\sentence_... \n", + "10 DE\\10.buchsederpandora_1501_librivox\\sentence_... \n", + "10 DE\\10.buchsederpandora_1501_librivox\\sentence_... \n", + "10 DE\\10.buchsederpandora_1501_librivox\\sentence_... \n", + "\n", + " EN_audio score \\\n", + "book_id \n", + "10 EN\\10.pandora\\sentence_level_audio\\00001-f0000... 0.508904 \n", + "10 EN\\10.pandora\\sentence_level_audio\\00001-f0000... 0.625685 \n", + "10 EN\\10.pandora\\sentence_level_audio\\00001-f0000... 0.262500 \n", + "10 EN\\10.pandora\\sentence_level_audio\\00001-f0000... 0.500168 \n", + "10 EN\\10.pandora\\sentence_level_audio\\00001-f0000... 0.845455 \n", + "\n", + " DE_transcript \\\n", + "book_id \n", + "10 Prachtvoller Saal in deutscher Renaissance mit... \n", + "10 In der Mitte unter der Galerie befindet sich d... \n", + "10 Links vorn ein kleiner Serviertisch, daneben e... \n", + "10 Der Saal ist durch eine auf dem Mitteltisch st... \n", + "10 Alwa Schön geht vor der Eingangstür auf und ni... \n", + "\n", + " EN_transcript \n", + "book_id \n", + "10 ACT I The hall of EARTHSPIRIT, , feebly lighte... \n", + "10 ACT I The hall of EARTHSPIRIT, , feebly lighte... \n", + "10 The firescreen and the chair by the ottoman ar... \n", + "10 Down left is a small teatable, with a coffeepo... \n", + "10 In this chair, deep in cushions, with a plaid ... \n", + "total number of samples in the alignment file: 25604\n" + ] + } + ], + "source": [ + "# display the dataframe\n", + "allignment = pd.read_csv(\"alignments/all_de_en_alligned_cleaned.csv\",index_col=0)\n", + "print(allignment.head())\n", + "print(\"total number of samples in the alignment file:\",len(allignment))" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "number of samples loaded in the dataset: 25604\n" + ] + } + ], + "source": [ + "dataset = Libris2sDataset(\n", + " data_dir=\".\",\n", + " split=\"alignments/all_de_en_alligned_cleaned.csv\", \n", + ")\n", + "print(\"number of samples loaded in the dataset:\",len(dataset))" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "# Get a sample\n", + "sample = dataset[123]\n", + "\n", + "# Access the data\n", + "de_audio = sample['de_audio'] # German audio waveform\n", + "en_audio = sample['en_audio'] # English audio waveform\n", + "de_sample_rate = sample['de_sample_rate']\n", + "en_sample_rate = sample['en_sample_rate']\n", + "de_text = sample['de_transcript'] # German transcript\n", + "en_text = sample['en_transcript'] # English transcript\n", + "score = sample['alignment_score'] # Alignment quality score" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "from IPython.display import display, HTML, Audio\n", + "\n", + "def display_alignment_sample(sample):\n", + " de_audio = sample['de_audio']\n", + " en_audio = sample['en_audio']\n", + " de_sample_rate = sample['de_sample_rate']\n", + " en_sample_rate = sample['en_sample_rate']\n", + " de_text = sample['de_transcript']\n", + " en_text = sample['en_transcript']\n", + " score = sample['alignment_score']\n", + "\n", + " html = f\"\"\"\n", + "

🔗 Alignment Sample

\n", + "

Alignment Score: {score:.3f}

\n", + " \n", + "

German

\n", + "

Transcript: {de_text}

\n", + " \"\"\"\n", + " display(HTML(html))\n", + " display(Audio(de_audio.numpy(), rate=de_sample_rate))\n", + " \n", + " html = f\"\"\"\n", + "

English

\n", + "

Transcript: {en_text}

\n", + " \"\"\"\n", + " display(HTML(html))\n", + " display(Audio(en_audio.numpy(), rate=en_sample_rate))\n" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "

🔗 Alignment Sample

\n", + "

Alignment Score: 0.907

\n", + "\n", + "

German

\n", + "

Transcript: Wenn ich eben Fräulein von Geschwitz darum bat, meine Hilfe anzunehmen, so geschah es gewiß nicht, um Ihre unersättliche Goldgier aufzustacheln.

\n", + " " + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "\n", + " \n", + " " + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "\n", + "

English

\n", + "

Transcript: When I asked Fräulein von Geschwitz just now to accept my help, it certainly was not to incite your insatiable avarice.

\n", + " " + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "\n", + " \n", + " " + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "display_alignment_sample(sample)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "cerba", + "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.6" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}