{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "e15b11ff", "metadata": {}, "outputs": [], "source": [ "from glob import glob\n", "import pickle\n", "import random" ] }, { "cell_type": "code", "execution_count": 6, "id": "c0b0850a", "metadata": {}, "outputs": [], "source": [ "speech_filenames = glob(\"Female/*/*.wav\") + glob(\"Male/*/*.wav\") + glob(\"NoNoise/*.wav\")" ] }, { "cell_type": "code", "execution_count": 7, "id": "4b02aef0", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "539" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "len_files = len(speech_filenames)\n", "len_files" ] }, { "cell_type": "code", "execution_count": 8, "id": "fd79d77b", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'Female/TMIT/SX243.wav'" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "speech_filenames[0]" ] }, { "cell_type": "code", "execution_count": 9, "id": "43554c74", "metadata": {}, "outputs": [], "source": [ "with open('total_files_path.txt', 'wb') as handle:\n", " pickle.dump(speech_filenames, handle)" ] }, { "cell_type": "code", "execution_count": 10, "id": "b2d5c828", "metadata": {}, "outputs": [], "source": [ "with open('total_files_path.txt', 'rb') as handle:\n", " b = pickle.load(handle)" ] }, { "cell_type": "code", "execution_count": 11, "id": "00ec128c", "metadata": {}, "outputs": [], "source": [ "random.shuffle(b)\n", "random.shuffle(b)\n", "random.shuffle(b)\n", "random.shuffle(b)" ] }, { "cell_type": "code", "execution_count": 12, "id": "bdd539cf", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['Male/PTDB-TUG/mic_M02_sx78.wav',\n", " 'Female/TMIT/SX150.wav',\n", " 'Female/PTDB-TUG/mic_F01_sx16.wav',\n", " 'Female/TMIT/SI485.wav',\n", " 'Female/PTDB-TUG/mic_F07_si1593.wav']" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "b[:5]" ] }, { "cell_type": "code", "execution_count": 13, "id": "e03922fb", "metadata": {}, "outputs": [], "source": [ "train_ratio = 0.80\n", "val_ratio = 0.10\n", "test_ratio = 0.10\n", "\n", "train_n = int(len_files*train_ratio)\n", "val_n = int(len_files*val_ratio)\n", "test_n = int(len_files*test_ratio)" ] }, { "cell_type": "code", "execution_count": 14, "id": "cffab26e", "metadata": {}, "outputs": [], "source": [ "train_files = b[:train_n]\n", "val_files = b[train_n:train_n + val_n]\n", "test_files = b[train_n + val_n:train_n + val_n + test_n]" ] }, { "cell_type": "code", "execution_count": 15, "id": "c031a7d6", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(431, 53, 53)" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "len(train_files),len(val_files),len(test_files)" ] }, { "cell_type": "code", "execution_count": 16, "id": "71188f4b", "metadata": {}, "outputs": [], "source": [ "with open('train_files_path.txt', 'wb') as handle:\n", " pickle.dump(train_files, handle)\n", " \n", "with open('validation_files_path.txt', 'wb') as handle:\n", " pickle.dump(val_files, handle)\n", " \n", "with open('test_files_path.txt', 'wb') as handle:\n", " pickle.dump(test_files, handle)" ] }, { "cell_type": "code", "execution_count": null, "id": "6296f7d8", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "6de6f440", "metadata": {}, "outputs": [], "source": [] } ], "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.9.16" } }, "nbformat": 4, "nbformat_minor": 5 }