diff --git a/examples.ipynb b/examples.ipynb new file mode 100644 index 0000000..2d1c6c8 --- /dev/null +++ b/examples.ipynb @@ -0,0 +1,159 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "a2cd4050", + "metadata": {}, + "outputs": [], + "source": [ + "from transcribe import transcribe" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "9fd18544", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Help on function transcribe in module transcribe:\n", + "\n", + "transcribe(path, file_type, model=None, language=None, verbose=True)\n", + " Implementation of OpenAI's whisper model. Downloads model, transcribes audio files in a folder and returns the text files with transcriptions\n", + "\n" + ] + } + ], + "source": [ + "help(transcribe)" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "ae6c21be", + "metadata": {}, + "outputs": [], + "source": [ + "path='sample_audio/'\n", + "file_type='ogg' #check your file for file type, will only transcribe files with the file type, 'ogg', 'WAV', etc.\n", + "model='medium' #'small', 'medium', 'large' (tradeoff between speed and accuracy)\n", + "language= None #tries to auto-detect, other options include 'English', 'Spanish', etc...\n", + "verbose = True # gets output while transcribing, False to deactivate" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ec98e379", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Using medium model, you can change this by specifying model=\"medium\" for example\n", + "Only looking for file type ogg, you can change this by specifying file_type=\"mp3\"\n", + "Expecting None language, you can change this by specifying language=\"English\". None will try to auto-detect\n", + "Verbosity is True. If TRUE it will print out the text as it is transcribed, you can turn this off by setting verbose=False\n", + "\n", + "There are 2 ogg files in path: sample_audio/\n", + "\n", + "\n", + "Loading model...\n", + "Transcribing file number number 1: sample_audio\\audio_1.ogg\n", + "Model and file loaded...\n", + "Starting transcription...\n", + "\n", + "Detecting language using up to the first 30 seconds. Use `--language` to specify the language\n", + "Detected language: Swedish\n", + "[00:00.000 --> 00:16.000] Hej, jag heter Axel Pettersson, jag föddes i Örebro 1976. Jag har varit Wikipedia sen 2008 och jag har översatt röstintroduktionsprojektet till svenska.\n", + "\n", + "Finished file number 1.\n", + "\n", + "\n", + "\n", + "Transcribing file number number 2: sample_audio\\audio_2.ogg\n", + "Model and file loaded...\n", + "Starting transcription...\n", + "\n", + "Detecting language using up to the first 30 seconds. Use `--language` to specify the language\n", + "Detected language: English\n", + "[00:00.000 --> 00:07.360] We're joined once again by our travel expert and also author of America's Top Roller Coasters\n", + "[00:07.360 --> 00:09.200] in Amusement Parks, Pete Tribuco.\n", + "[00:09.200 --> 00:11.040] Good morning and welcome back to Daybreak USA.\n", + "[00:11.040 --> 00:13.480] Well, thanks for having me on.\n", + "[00:13.480 --> 00:18.900] If someone's lucky enough to go on vacation to an exotic location and then maybe not so\n", + "[00:18.900 --> 00:24.860] lucky to have some kind of a disaster happen while they're there, maybe some civil unrest,\n", + "[00:24.860 --> 00:26.200] what should they do now?\n", + "[00:26.200 --> 00:27.200] What's the next step?\n", + "[00:27.840 --> 00:31.560] Well, whenever you're going on vacation, whether it's locally or internationally, you've got\n", + "[00:31.560 --> 00:33.080] to be very careful.\n", + "[00:33.080 --> 00:38.880] Obviously, natural disasters, they pop up, or man-made disasters pop up pretty quickly.\n", + "[00:38.880 --> 00:42.800] You want to make sure that you've got a few things when you're on vacation that's important.\n", + "[00:42.800 --> 00:45.100] Number one, always stay informed.\n", + "[00:45.100 --> 00:48.640] When you're traveling, it's easy to find yourself, you know, distant from the world.\n", + "[00:48.640 --> 00:51.920] Always know what's happening in that area that you're going to.\n", + "[00:51.920 --> 00:55.840] You know, always check and see what the conditions are.\n", + "[00:55.880 --> 01:00.480] And sometimes it's a place you might not want to go to, so always check that.\n", + "[01:00.480 --> 01:04.160] And, you know, of course, check out all the different weather alerts.\n", + "[01:04.160 --> 01:09.200] If it's a hurricane season, for example, make sure that you're aware of that.\n", + "[01:09.200 --> 01:14.600] If an incident does happen, stay with a group, get a buddy, you know, travel with a buddy\n", + "[01:14.600 --> 01:18.880] or somebody that you can basically go to so that you're not alone.\n", + "[01:18.880 --> 01:24.040] Obviously, you want to make sure that if there's any type of a disaster, that you have a plan\n", + "[01:24.040 --> 01:25.040] in place.\n", + "[01:25.080 --> 01:30.440] Now, the one big thing I think everyone should do is invest in travel insurance.\n", + "[01:30.440 --> 01:35.000] No matter where you are, no matter where you go, if you have that insurance program in\n", + "[01:35.000 --> 01:40.480] place and know what the limitations and scenarios that it covers, it's good to have it.\n", + "[01:40.480 --> 01:44.880] It's well worth paying the little extra dollars to enjoy your vacation.\n", + "[01:44.880 --> 01:49.080] And, of course, connect back with your home base, you know.\n", + "[01:49.080 --> 01:53.680] When you travel, you want to let people know where you're at, where you're going to be.\n", + "[01:53.720 --> 01:58.320] Maybe have an itinerary with the embassy if you're going, you know, overseas and make\n", + "[01:58.320 --> 02:01.440] sure that everyone knows where you're at at any given time.\n", + "[02:01.440 --> 02:07.080] And, of course, during a disaster, the American Red Cross is pretty much everywhere.\n", + "[02:07.080 --> 02:12.960] You want to find a location, depending on the situation of what has happened.\n", + "[02:12.960 --> 02:17.960] And they'll be able to set you up, you know, with care packages and stuff along those lines.\n", + "[02:17.960 --> 02:18.960] Great advice, Pete.\n", + "[02:18.960 --> 02:21.160] Do you have a website where you can get more information?\n" + ] + } + ], + "source": [ + "transcribe(path, file_type, model, language, verbose)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6002cf16", + "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.10.4" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/examples/examples.ipynb b/examples/examples.ipynb deleted file mode 100644 index 363fcab..0000000 --- a/examples/examples.ipynb +++ /dev/null @@ -1,6 +0,0 @@ -{ - "cells": [], - "metadata": {}, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/examples/readme.MD b/examples/readme.MD deleted file mode 100644 index 41a6341..0000000 --- a/examples/readme.MD +++ /dev/null @@ -1 +0,0 @@ -### examples diff --git a/sample_audio/audio_1.ogg b/sample_audio/audio_1.ogg new file mode 100644 index 0000000..b7c3922 Binary files /dev/null and b/sample_audio/audio_1.ogg differ diff --git a/sample_audio/audio_2.ogg b/sample_audio/audio_2.ogg new file mode 100644 index 0000000..fe76321 Binary files /dev/null and b/sample_audio/audio_2.ogg differ diff --git a/sample_audio/transcriptions/audio_1.txt b/sample_audio/transcriptions/audio_1.txt new file mode 100644 index 0000000..5eec43a --- /dev/null +++ b/sample_audio/transcriptions/audio_1.txt @@ -0,0 +1,3 @@ +audio_1 +In seconds: +[0.00 --> 16.00]: Hej, jag heter Axel Pettersson, jag föddes i Örebro 1976. Jag har varit Wikipedia sen 2008 och jag har översatt röstintroduktionsprojektet till svenska. \ No newline at end of file diff --git a/sample_audio/transcriptions/audio_2.txt b/sample_audio/transcriptions/audio_2.txt new file mode 100644 index 0000000..e9eaeb5 --- /dev/null +++ b/sample_audio/transcriptions/audio_2.txt @@ -0,0 +1,47 @@ +audio_2 +In seconds: +[0.00 --> 7.36]: We're joined once again by our travel expert and also author of America's Top Roller Coasters +[7.36 --> 9.20]: in Amusement Parks, Pete Tribuco. +[9.20 --> 11.04]: Good morning and welcome back to Daybreak USA. +[11.04 --> 13.48]: Well, thanks for having me on. +[13.48 --> 18.90]: If someone's lucky enough to go on vacation to an exotic location and then maybe not so +[18.90 --> 24.86]: lucky to have some kind of a disaster happen while they're there, maybe some civil unrest, +[24.86 --> 26.20]: what should they do now? +[26.20 --> 27.20]: What's the next step? +[27.84 --> 31.56]: Well, whenever you're going on vacation, whether it's locally or internationally, you've got +[31.56 --> 33.08]: to be very careful. +[33.08 --> 38.88]: Obviously, natural disasters, they pop up, or man-made disasters pop up pretty quickly. +[38.88 --> 42.80]: You want to make sure that you've got a few things when you're on vacation that's important. +[42.80 --> 45.10]: Number one, always stay informed. +[45.10 --> 48.64]: When you're traveling, it's easy to find yourself, you know, distant from the world. +[48.64 --> 51.92]: Always know what's happening in that area that you're going to. +[51.92 --> 55.84]: You know, always check and see what the conditions are. +[55.88 --> 60.48]: And sometimes it's a place you might not want to go to, so always check that. +[60.48 --> 64.16]: And, you know, of course, check out all the different weather alerts. +[64.16 --> 69.20]: If it's a hurricane season, for example, make sure that you're aware of that. +[69.20 --> 74.60]: If an incident does happen, stay with a group, get a buddy, you know, travel with a buddy +[74.60 --> 78.88]: or somebody that you can basically go to so that you're not alone. +[78.88 --> 84.04]: Obviously, you want to make sure that if there's any type of a disaster, that you have a plan +[84.04 --> 85.04]: in place. +[85.08 --> 90.44]: Now, the one big thing I think everyone should do is invest in travel insurance. +[90.44 --> 95.00]: No matter where you are, no matter where you go, if you have that insurance program in +[95.00 --> 100.48]: place and know what the limitations and scenarios that it covers, it's good to have it. +[100.48 --> 104.88]: It's well worth paying the little extra dollars to enjoy your vacation. +[104.88 --> 109.08]: And, of course, connect back with your home base, you know. +[109.08 --> 113.68]: When you travel, you want to let people know where you're at, where you're going to be. +[113.72 --> 118.32]: Maybe have an itinerary with the embassy if you're going, you know, overseas and make +[118.32 --> 121.44]: sure that everyone knows where you're at at any given time. +[121.44 --> 127.08]: And, of course, during a disaster, the American Red Cross is pretty much everywhere. +[127.08 --> 132.96]: You want to find a location, depending on the situation of what has happened. +[132.96 --> 137.96]: And they'll be able to set you up, you know, with care packages and stuff along those lines. +[137.96 --> 138.96]: Great advice, Pete. +[138.96 --> 141.16]: Do you have a website where you can get more information? +[141.40 --> 148.84]: Yes, it is www.americasrollercoasters.tatepublishing.net. +[148.84 --> 149.84]: Excellent, Pete. +[149.84 --> 150.84]: Thanks so much. +[150.84 --> 155.72]: And hopefully, hopefully that'll keep some people safe on their big vacation this summer. +[155.72 --> 161.28]: At least having that information should help people feel a little safer anyway. +[161.28 --> 162.28]: It sure would. +[162.28 --> 163.28]: Thank you so much, sir. +[163.28 --> 164.28]: We'll talk again soon. +[164.28 --> 165.28]: Have a great day. \ No newline at end of file diff --git a/transcribe.py b/transcribe.py index 08ebf69..92a4f9a 100644 --- a/transcribe.py +++ b/transcribe.py @@ -1,10 +1,9 @@ import whisper import glob, os -def transcribe(path, file_type, model='base', language=None, verbose=True): - '''Implementation of OpenAI's whisper model. Downloads model, transcribes audio files - in a folder and returns the text files with transcriptions.''' - +def transcribe(path, file_type, model=None, language=None, verbose=True): + '''Implementation of OpenAI's whisper model. Downloads model, transcribes audio files in a folder and returns the text files with transcriptions''' + try: os.mkdir('{}transcriptions'.format(path)) except FileExistsError: