{"id":10750,"date":"2023-09-29T18:00:00","date_gmt":"2023-09-29T18:00:00","guid":{"rendered":"https:\/\/businessyield.com\/tech\/?p=10750"},"modified":"2023-09-27T20:33:55","modified_gmt":"2023-09-27T20:33:55","slug":"openai-whisper-how-does-openai-whisper-work","status":"publish","type":"post","link":"https:\/\/businessyield.com\/tech\/technology\/openai-whisper-how-does-openai-whisper-work\/","title":{"rendered":"OpenAI Whisper: How Does OpenAI Whisper Work?","gt_translate_keys":[{"key":"rendered","format":"text"}]},"content":{"rendered":"\n
OpenAI recently launched the Whisper API, a hosted version of the open-source Whisper speech-to-text model to coincide with the release of ChatGPT API. <\/p>\n\n\n\n
Priced at $0.006 per minute, Whisper is an automatic speech recognition system that OpenAI claims enables \u201crobust\u201d transcription in multiple languages as well as translation from those languages into English. It takes files in a variety of formats, including M4A, MP3, MP4, MPEG, MPGA, WAV, and WEBM.<\/p>\n\n\n\n
Countless organizations have developed highly capable speech recognition systems, which sit at the core of software and services from tech giants like Google, Amazon, and Meta. However, what sets Whisper apart is that it was trained on 680,000 hours of multilingual and \u201cmultitask\u201d data collected from the web. <\/p>\n\n\n\n
This leads to improved recognition of unique accents, background noise, and technical jargon.<\/p>\n\n\n\n
Whisper is an automatic speech recognition model trained on 680,000 hours of multilingual data collected from the web. As per OpenAI, this model is robust to accents, background noise, and technical language. In addition, it supports 99 different languages\u2019 transcription and translation from those languages into English.<\/p>\n\n\n\n
Whisper has five models (refer to the below table). Below is the table available on OpenAI\u2019s GitHub page. According to OpenAI, there are four models for English-only applications, which are denoted as The Whisper models are trained for speech recognition and translation tasks, capable of transcribing speech audio into the text in the language it is spoken (ASR) as well as translated into English (speech translation). Whisper is an Encoder-Decoder model, trained on 680,000 hours of multilingual and multitask supervised data collected from the web. <\/p>\n\n\n\n Transcription is a process of converting spoken language into text. In the past, it was done manually; now, there are AI-powered tools like Whisper that can accurately understand spoken language. With a basic knowledge of Python language, you can integrate OpenAI Whisper API into your application. <\/p>\n\n\n\n The Whisper API is a part of openai\/openai-python, which allows you to access various OpenAI services and models.<\/p>\n\n\n\n Input audio is split into 30-second chunks, converted into a log-Mel spectrogram, and then passed into an encoder. A decoder is trained to predict the corresponding text caption, intermixed with special tokens that direct the single model to perform tasks such as language identification, phrase-level timestamps, multilingual speech transcription, and to-English speech translation.<\/p>\n\n\n\n In simpler words, OpenAI Whisper is built on the transformer architecture, stacking encoder blocks and decoder blocks with the attention mechanism propagating information between both.<\/p>\n\n\n\n It will take the audio recording, split it into 30-second chunks and process them one by one. For each 30-second recording, it will encode the audio using the encoder section and save the position of each word said. Then, it will leverage this encoded information to find what was said using the decoder.<\/p>\n\n\n\n The decoder will predict what we call tokens from all this information, which is basically each word that is said. Then, it will repeat this process for the next word using all the same information as well as the predicted previous word, helping it guess the next one that would make more sense.<\/p>\n\n\n\n OpenAI trained Whisper’s audio model in a similar way as GPT-3 – with data available on the internet. This makes it a large and general audio model. It also makes the model way more robust than others. In fact, according to OpenAI, Whisper approaches human-level robustness due to being trained on such a diverse set of data ranging from clips, TED talks, podcasts, interviews, and more. <\/p>\n\n\n\n All of these represent real-world-like data, with some of them transcribed using machine learning-based models and not humans.<\/p>\n\n\n\n The speech-to-text API provides two endpoints – transcriptions and translations – based on OpenAI’s state-of-the-art open-source large-v2 Whisper model. They can be used to:<\/p>\n\n\n\n File uploads are currently limited to 25 MB and the following input file types are supported: The transcriptions API takes as input the audio file you want to transcribe and the desired output file format for the transcription of the audio. It currently supports multiple input and output file formats.<\/p>\n\n\n By default, the response type will be json with the raw text included.<\/p>\n\n\n\n To set additional parameters in a request, you can add more The translations API takes as input the audio file in any of the supported languages and transcribes, if necessary, the audio into English. This differs from OpennAI’s \/Transcriptions endpoint since the output is not in the original input language and is instead translated into English text.<\/p>\n\n\n In this case, the inputted audio was German and the outputted text looks like this:<\/p>\n\n\n\n OpenAI Whisper API supports the following languages for transcriptions and translations:<\/p>\n\n\n\n Afrikaans. Arabic. Armenian. Azerbaijani. Belarusian. Bosnian. Bulgarian. Catalan. Chinese. Croatian. Czech. Danish. Dutch. English. Estonian. Finnish. French. Galician. German. Greek. Hebrew. Hindi. Hungarian. Icelandic. Indonesian. Italian. Japanese. Kannada. Kazakh. Korean. Latvian. Lithuanian. Macedonian. Malay. Marathi. Maori. Nepali. Norwegian. Persian. Polish. Portuguese. Romanian. Russian. Serbian. Slovak. Slovenian. Spanish. Swahili. Swedish. Tagalog. Tamil. Thai. Turkish. Ukrainian. Urdu. Vietnamese. Welsh.<\/p>\n\n\n\n The breakdown of the Word Error Rate (WER) for Fleur’s dataset using the large-v2 model is presented in the figure below, categorized by languages. The smaller the WER, the better the transcription accuracy. <\/p>\n\n\n Whisper API supports the following file formats: The following command will transcribe speech in audio files, using the The default setting (which selects the Adding Run the following to view all available options:<\/p>\n\n\n\n See tokenizer.py<\/a> for the list of all available languages.<\/a><\/p>\n\n\n\n By default, the Whisper API only supports files that are less than 25 MB. If you have an audio file that is longer than that, you will need to break it up into chunks of 25 MB or less or use a compressed audio format. To get the best performance, we suggest that you avoid breaking the audio up mid-sentence as this may cause some context to be lost.<\/p>\n\n\n\n One way to handle this is to use the PyDub open-source Python package<\/a> to split the audio:<\/p>\n\n\n\n You can use a prompt to improve the quality of the transcripts generated by the Whisper API. The model will try to match the style of the prompt, so it will be more likely to use capitalization and punctuation if the prompt does too. <\/p>\n\n\n\n However, the current prompting system is much more limited than other language models and only provides limited control over the generated audio. <\/p>\n\n\n\n Having such a general model isn\u2019t very powerful in itself, as it will be beaten at most tasks by smaller and more specific models adapted to the task at hand. But it has other benefits. You can use this kind of pre-trained models and fine-tune them on your task. This means that you will take this powerful model and retrain a part of it, or the entire thing, with your own data. <\/p>\n\n\n\n This technique has been shown to produce much better models than starting training from scratch with your data.<\/p>\n\n\n\n Another benefit is that OpenAI open-sourced its code and everything instead of an API. This means you can use Whisper as a pre-trained foundation architecture to build upon and create more powerful models for yourself.<\/p>\n\n\n\n.en<\/code>. The model performs better for tiny.en<\/code> and base.en<\/code>, but differences become less significant for the small.en<\/code> and medium.en<\/code> models.<\/p>\n\n\n\n
What are good use cases for transcription?<\/strong><\/span><\/h2>\n\n\n\n
\n
How does Whisper work?<\/strong><\/span><\/h2>\n\n\n\n
How to use OpenAI Whisper<\/strong><\/span><\/h2>\n\n\n\n
\n
mp3<\/code>, mp4<\/code>, mpeg<\/code>, mpga<\/code>, m4a<\/code>, wav<\/code>, and webm<\/code>.<\/p>\n\n\n\n<\/a>Quickstart <\/strong><\/span><\/h3>\n\n\n\n
Transcriptions<\/strong><\/span><\/h4>\n\n\n\n
<\/figure><\/div>\n\n\n{ \n \"text\": \"Imagine the wildest idea that you've ever had, and you're curious about how it might scale to something that's a 100, a 1,000 times bigger. \n.... \n}<\/pre>\n\n\n\n--form<\/code> lines with the relevant options. For example, if you want to set the output format as text, you would add the following line:<\/p>\n\n\n\n1 ...\n2 --form file=@openai.mp3 \\\n3 --form model=whisper-1 \\\n4 --form response_format=text<\/code><\/pre>\n\n\n\n<\/a>Translations<\/strong><\/span><\/h4>\n\n\n\n
<\/figure><\/div>\n\n\nHello, my name is Wolfgang and I come from Germany. Where are you heading today?<\/pre>\n\n\n\n
Features of OpenAI Whisper<\/strong><\/span><\/h2>\n\n\n\n
Languages<\/strong><\/span><\/h3>\n\n\n\n
<\/figure><\/div>\n\n\nFile formats<\/strong><\/span><\/h3>\n\n\n\n
mp3<\/code>, mp4<\/code>, mpeg<\/code>, mpga<\/code>, m4a<\/code>, wav<\/code>, and webm<\/code>. Currently, upload file size is limited to 25MB. If you have larger files, you can break them down into smaller chunks using pydub<\/a>.<\/p>\n\n\n\nCommand-line usage<\/strong><\/span><\/h3>\n\n\n\n
medium<\/code> model:<\/p>\n\n\n\nwhisper audio.flac audio.mp3 audio.wav --model medium\n<\/code><\/pre>\n\n\n\nsmall<\/code> model) works well for transcribing English. To transcribe an audio file containing non-English speech, you can specify the language using the --language<\/code> option:<\/p>\n\n\n\nwhisper japanese.wav --language Japanese\n<\/code><\/pre>\n\n\n\n--task translate<\/code> will translate the speech into English:<\/p>\n\n\n\nwhisper japanese.wav --language Japanese --task translate\n<\/code><\/pre>\n\n\n\nwhisper --help\n<\/code><\/pre>\n\n\n\nLonger inputs<\/strong><\/h3>\n\n\n\n
1 from pydub import AudioSegment\n2\n3 song = AudioSegment.from_mp3(\"good_morning.mp3\")\n4\n5 # PyDub handles time in milliseconds\n6 ten_minutes = 10 * 60 * 1000\n7\n8 first_10_minutes = song[:ten_minutes]\n9\n10 first_10_minutes.export(\"good_morning_10.mp3\", format=\"mp3\")<\/code><\/pre>\n\n\n\n<\/a>Prompting<\/strong><\/span><\/h3>\n\n\n\n
Here are some examples of how prompting can help in different scenarios:<\/strong><\/span><\/h5>\n\n\n\n
\n
In conclusion<\/strong><\/span><\/h2>\n\n\n\n
Recommended Articles<\/strong><\/span><\/h2>\n\n\n\n
\n
References<\/strong><\/span><\/h2>\n\n\n\n
\n