Complete rework for GUI, experimental EXE file and other minor changes, see readme for more info
This commit is contained in:
119
example.ipynb
119
example.ipynb
@@ -1,123 +1,125 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"id": "a2cd4050",
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from transcribe import transcribe"
|
||||
"# Local Transcribe with Whisper\n",
|
||||
"## Example"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"id": "24e1d24e",
|
||||
"execution_count": 1,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Help on function transcribe in module transcribe:\n",
|
||||
"Help on function transcribe in module src._LocalTranscribe:\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",
|
||||
"transcribe(path, glob_file, model=None, language=None, verbose=False)\n",
|
||||
" Transcribes audio files in a specified folder using OpenAI's Whisper model.\n",
|
||||
" \n",
|
||||
" Args:\n",
|
||||
" path (str): Path to the folder containing the audio files.\n",
|
||||
" glob_file (list): List of audio file paths to transcribe.\n",
|
||||
" model (str, optional): Name of the Whisper model to use for transcription.\n",
|
||||
" Defaults to None, which uses the default model.\n",
|
||||
" language (str, optional): Language code for transcription. Defaults to None,\n",
|
||||
" which enables automatic language detection.\n",
|
||||
" verbose (bool, optional): If True, enables verbose mode with detailed information\n",
|
||||
" during the transcription process. Defaults to False.\n",
|
||||
" \n",
|
||||
" Returns:\n",
|
||||
" str: A message indicating the result of the transcription process.\n",
|
||||
" \n",
|
||||
" Raises:\n",
|
||||
" RuntimeError: If an invalid file is encountered, it will be skipped.\n",
|
||||
" \n",
|
||||
" Notes:\n",
|
||||
" - The function downloads the specified model if not available locally.\n",
|
||||
" - The transcribed text files will be saved in a \"transcriptions\" folder\n",
|
||||
" within the specified path.\n",
|
||||
"\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# Import the modules and get the docstring\n",
|
||||
"from src._LocalTranscribe import transcribe, get_path\n",
|
||||
"help(transcribe)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"id": "e52477fb",
|
||||
"execution_count": 2,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"path='sample_audio/'#folder path\n",
|
||||
"file_type='ogg' #check your file for file type, will only transcribe those files\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 # prints output while transcribing, False to deactivate"
|
||||
"# Set the variables\n",
|
||||
"path='sample_audio/'# Folder path\n",
|
||||
"model='small' # Model size\n",
|
||||
"language= None # Preset language, None for automatic detection\n",
|
||||
"verbose = True # Output transcription in realtime\n",
|
||||
"\n",
|
||||
"# Get glob file, additional step for app version.\n",
|
||||
"\n",
|
||||
"glob_file = get_path(path)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"id": "d66866af",
|
||||
"execution_count": 3,
|
||||
"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: Armstrong_Small_Step\n",
|
||||
"Model and file loaded...\n",
|
||||
"Starting transcription...\n",
|
||||
"\n",
|
||||
"Trying to transcribe file named: Armstrong_Small_Step🕐\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:24.000] That's one small step for man, one giant leap for mankind.\n",
|
||||
"\n",
|
||||
"Finished file number 1.\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"Transcribing file number number 2: Axel_Pettersson_röstinspelning\n",
|
||||
"Model and file loaded...\n",
|
||||
"Starting transcription...\n",
|
||||
"[00:00.000 --> 00:07.000] I'm going to step off the limb now.\n",
|
||||
"[00:07.000 --> 00:18.000] That's one small step for man.\n",
|
||||
"[00:18.000 --> 00:24.000] One giant leap for mankind.\n",
|
||||
"\n",
|
||||
"Trying to transcribe file named: Axel_Pettersson_röstinspelning🕐\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",
|
||||
"[00:00.000 --> 00:06.140] Hej, jag heter Axel Pettersson. Jag följer bror 1976.\n",
|
||||
"[00:06.400 --> 00:15.100] Jag har varit vikerpedjan sen 2008 och jag har översatt röstintroduktionsprojektet till svenska.\n",
|
||||
"\n",
|
||||
"Finished file number 2.\n",
|
||||
"Trying to transcribe file named: readme🕐\n",
|
||||
"Not a valid file, skipping.\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"\n"
|
||||
"Trying to transcribe file named: transcriptions🕐\n",
|
||||
"Not a valid file, skipping.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"'Finished transcription, files can be found in sample_audio/transcriptions'"
|
||||
"'Finished transcription, 2 files can be found in sample_audio//transcriptions'"
|
||||
]
|
||||
},
|
||||
"execution_count": 4,
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"transcribe(path, file_type, model, language, verbose)"
|
||||
"# Run the script\n",
|
||||
"transcribe(path, glob_file, model, language, verbose)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "0bc67265",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"display_name": "venv",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
@@ -132,8 +134,9 @@
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.10.4"
|
||||
}
|
||||
},
|
||||
"orig_nbformat": 4
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user