{"id":20445142,"url":"https://github.com/hetpandya/youtube_tts_data_generator","last_synced_at":"2026-03-11T18:34:01.042Z","repository":{"id":49458198,"uuid":"300668475","full_name":"hetpandya/youtube_tts_data_generator","owner":"hetpandya","description":"A python library to generate speech dataset from Youtube videos","archived":false,"fork":false,"pushed_at":"2024-06-07T08:03:04.000Z","size":83,"stargazers_count":36,"open_issues_count":2,"forks_count":8,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-26T18:43:44.339Z","etag":null,"topics":["dataset-generator","python-library","speech-dataset","text-to-speech","text-to-speech-dataset","tts","tts-dataset","youtube","youtube-dataset","youtube-dataset-generator"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hetpandya.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2020-10-02T16:06:10.000Z","updated_at":"2025-01-13T17:59:46.000Z","dependencies_parsed_at":"2022-07-30T16:39:10.322Z","dependency_job_id":"d22f06e8-8c81-4953-adf3-ff7d82bcc829","html_url":"https://github.com/hetpandya/youtube_tts_data_generator","commit_stats":null,"previous_names":["thehetpandya/youtube_tts_data_generator"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hetpandya%2Fyoutube_tts_data_generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hetpandya%2Fyoutube_tts_data_generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hetpandya%2Fyoutube_tts_data_generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hetpandya%2Fyoutube_tts_data_generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hetpandya","download_url":"https://codeload.github.com/hetpandya/youtube_tts_data_generator/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248650414,"owners_count":21139672,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dataset-generator","python-library","speech-dataset","text-to-speech","text-to-speech-dataset","tts","tts-dataset","youtube","youtube-dataset","youtube-dataset-generator"],"created_at":"2024-11-15T10:11:07.945Z","updated_at":"2026-03-11T18:33:55.999Z","avatar_url":"https://github.com/hetpandya.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Youtube Speech Data Generator\r\n\r\n[![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://en.wikipedia.org/wiki/MIT_License)\r\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\r\n\u003ca href=\"https://pepy.tech/project/youtube-tts-data-generator\"\u003e\r\n    \u003cimg alt=\"Downloads\" src=\"https://pepy.tech/badge/youtube-tts-data-generator\"\u003e\r\n\u003c/a\u003e\r\n\r\nA python library to generate speech dataset. Youtube Speech Data Generator also takes care of almost all your speech data preprocessing needed to build a speech dataset along with their transcriptions making sure it follows a directory structure followed by most of the text-to-speech architectures.\r\n\r\n## Installation\r\nMake sure [ffmpeg](https://ffmpeg.org/download.html#get-packages) is installed and is set to the system path.\r\n\r\n```bash\r\n$ pip install youtube-tts-data-generator\r\n```\r\n\r\n## Minimal start for creating the dataset\r\n\r\n```python\r\nfrom youtube_tts_data_generator import YTSpeechDataGenerator\r\n\r\n# First create a YTSpeechDataGenerator instance:\r\n\r\ngenerator = YTSpeechDataGenerator(dataset_name='elon')\r\n\r\n# Now create a '.txt' file that contains a list of YouTube videos that contains speeches.\r\n# NOTE - Make sure you choose videos with subtitles.\r\n\r\ngenerator.prepare_dataset('links.txt')\r\n# The above will take care about creating your dataset, creating a metadata file and trimming silence from the audios.\r\n\r\n```\r\n\r\n## Usage\r\n\u003c!--ts--\u003e\r\n- Initializing the generator:\r\n  ```generator = YTSpeechDataGenerator(dataset_name='your_dataset',lang='en')```\r\n  - Parameters:\r\n    - *dataset_name*: \r\n      - The name of the dataset you'd like to give. \r\n      - A directory structure like this will be created:\r\n        ```\r\n        ├───your_dataset\r\n        │   ├───txts\r\n        │   └───wavs\r\n        └───your_dataset_prep\r\n            ├───concatenated\r\n            ├───downloaded\r\n            └───split\r\n        ```\r\n    - *output_type*: \r\n      - The type of the metadata to be created after the dataset has been generated.\r\n      - Supported types: csv/json\r\n      - Default output type is set to *csv*\r\n      - The csv file follows the format of [LJ Speech Dataset](https://keithito.com/LJ-Speech-Dataset/)\r\n      - The json file follows this format:\r\n        ```\r\n        {\r\n            \"your_dataset1.wav\": \"This is an example text\",\r\n            \"your_dataset2.wav\": \"This is an another example text\",\r\n        }\r\n        ```\r\n    - *keep_audio_extension*:\r\n      - Whether to keep the audio file extension in the metadata file\r\n      - Default value is set to *False*\r\n    - *lang*:\r\n      - The key for the target language in which the subtitles have to be downloaded.\r\n      - Default value is set to *en*\r\n      - *Tip* - check list of available languages and their keys using: `generator.get_available_langs()`\r\n    - *sr*:\r\n      - Sample Rate to keep of the audios.\r\n      - Default value is set to *22050*\r\n \r\n- Methods:\r\n  - download():\r\n    - Downloads video files from YouTube along with their subtitles and saves them as wav files.\r\n    - Parameters:\r\n      - *links_txt*:\r\n        - Path to the '.txt' file that contains the urls for the videos.\r\n    - Usage of this method is optional. If you do not use this method, make sure to place all the audio and subtitle files in 'your_dataset_prep/downloaded' directory. \r\n    - Then, create a file called 'files.txt' and again place it under 'your_dataset_prep/downloaded'.\r\n      'files.txt' should follow the following format:\r\n      ```\r\n      filename,subtitle,trim_min_begin,trim_min_end\r\n      audio.wav,subtitle.srt,0,0\r\n      audio2.wav,subtitle.vtt,5,6\r\n      ```\r\n    - Create a '.txt' file that contains a list of YouTube videos that contains speeches.\r\n    - Example - ```generator.download('links.txt')```\r\n  - split_audios():\r\n    - This method splits all the wav files into smaller chunks according to the duration of the text in the subtitles.\r\n    - Saves transcriptions as '.txt' file for each of the chunks.\r\n    - Example - ```generator.split_audios()```\r\n  - concat_audios():\r\n    - Since the split audios are based on the duration of their subtitles, they might not be so long. This method joins the split files into recognizable ones.\r\n    - Parameters:\r\n      - *max_limit*: \r\n        - The upper limit of length of the audios that should be concated. The rest will be kept as they are.\r\n        - The default value is set to *7*\r\n      - *concat_count*: \r\n        - The number of consecutive audios that should be concated together. \r\n        - The default value is set to *2*\r\n    - Example - ```generator.concat_audios()```\r\n  - finalize_dataset():\r\n    - Trims silence the joined audios since the data has been collected from YouTube and generates the final dataset after finishing all the preprocessing.\r\n    - Parameters:\r\n      - *min_audio_length*:\r\n        - The minumum length of the speech that should be kept. The rest will be ignored.\r\n        - The default value is set set to *5*.\r\n      - *max_audio_length*:\r\n        - The maximum length of the speech that should be kept. The rest will be ignored.\r\n        - The default value is set set to *14*.        \r\n    - Example - ```generator.finalize_dataset(min_audio_length=6)```\r\n  - get_available_langs():\r\n    - Get list of available languages in which the subtitles can be downloaded.\r\n    - Example - ```generator.get_available_langs()```\r\n  - get_total_audio_length():\r\n    - Returns the total amount of preprocessed speech data collected by the generator.\r\n    - Example - ```generator.get_total_audio_length()```\r\n  - prepare_dataset():\r\n    - A wrapper method for *download()*,*split_audios()*,*concat_audios()* and *finalize_dataset()*.\r\n    - If you do not wish to use the above methods, you can directly call *prepare_dataset()*. It will handle all your data generation.\r\n    - Parameters:\r\n      - *links_txt*:\r\n        - Path to the '.txt' file that contains the urls for the videos.\r\n      - *sr*:\r\n        - Sample Rate to keep of the audios.\r\n        - Default value is set to *22050*  \r\n      - *download_youtube_data*:\r\n        - Whether to download audios from YouTube.\r\n        - Default value is *True*\r\n      - *max_concat_limit*: \r\n        - The upper limit of length of the audios that should be concated. The rest will be kept as they are.\r\n        - The default value is set to *7*\r\n      - *concat_count*: \r\n        - The number of consecutive audios that should be concated together. \r\n        - The default value is set to *2*\r\n      - *min_audio_length*:\r\n        - The minumum length of the speech that should be kept. The rest will be ignored.\r\n        - The default value is set set to *5*.        \r\n      - *max_audio_length*:\r\n        - The maximum length of the speech that should be kept. The rest will be ignored.\r\n        - The default value is set set to *14*.        \r\n    - Example - ```generator.prepare_dataset(links_txt='links.txt',\r\n                                             download_youtube_data=True,\r\n                                             min_audio_length=6)```\r\n\u003c!--te--\u003e\r\n\r\n## Final dataset structure\r\nOnce the dataset has been created, the structure under 'your_dataset' directory should look like:\r\n```\r\nyour_dataset\r\n├───txts\r\n│   ├───your_dataset1.txt\r\n│   └───your_dataset2.txt\r\n├───wavs\r\n│    ├───your_dataset1.wav\r\n│    └───your_dataset2.wav\r\n└───metadata.csv/alignment.json\r\n```\r\n\r\nNOTE - `audio.py` is highly based on [Real Time Voice Cloning](https://github.com/CorentinJ/Real-Time-Voice-Cloning/blob/master/encoder/audio.py)\r\n\r\n## References\r\n[SRT to JSON](https://github.com/pgrabovets/srt-to-json)\r\n\r\n*Read more about the library [here](https://medium.com/@TheHetPandya/creating-your-own-text-to-speech-dataset-from-youtube-f1177845b12e)*\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhetpandya%2Fyoutube_tts_data_generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhetpandya%2Fyoutube_tts_data_generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhetpandya%2Fyoutube_tts_data_generator/lists"}