在Mac上使用Wishper在终端中立即转录音频和视频文件

使用相同的AI将Mac变成强大的转录机,该AI为OpenAI的Chatgpt提供动力。只需几个终端命令,您就可以在几分钟内将音频和视频文件转换为准确的文本。

如果您以前从未触及过终端,请不要担心 - 在Macos红杉15上设置低语比外观更容易,值得。无论您是使用YouTube视频,访谈,讲座还是语音笔记,低语都可以处理所有繁重的工作。

Whisper是OpenAI的免费,开源的语音到文本神经网络,完全在您的机器上运行 - 设置后不需要互联网。一旦完成,它就会快速,安全且死亡简单 - 它几乎可以通过您投入的任何音频或视频格式进行咀嚼。如果您厌倦了基于小故障网络的转录服务,昂贵的Mac应用程序以及具有限制(例如文件尺寸盖,水印,广告或糟糕的精度),这是一个完美的工具。

是的,它生活在码头中 - 大多数人避免的黑盒谜。但这是事实:如果您可以复制和粘贴,可以轻视。安装后,转录文件实际上是一行。没有腹胀的界面,没有上传和等待,也没有每月费用。

如果您还没有准备好弄乱命令行?您还有选择。 Mac Whisper和Whisper转录等Mac应用程序为您提供了一个拖放界面,并在引擎盖下用耳语提供动力。基于浏览器的服务,例如在拥抱脸上的耳语演示,使其变得更加容易 - 尽管您通常会为方便起来进行一些隐私和灵活性。但是,命令行版本仍然是使用低语的最强大和灵活的方式,这是Openai维护的官方实现。如果要完全控制,这是您想要的版本。

或者,您可以跳过所有内容,只需通过其网络或桌面应用程序发送changpt,它可以使用窃窃私语为您转录或翻译。

因此,如果您厌倦了跳过箍,只是为了获得干净的成绩单 - 无论您是学生,播客,记者还是只是试图存档缩放电话的人 - 现在该需要五分钟并设置一些刚起作用的东西了。让我们潜入。

要求

通过以下说明,您将使用以下工具安装和使用:

  • 来自Openai的Whisper命令行工具:将语音转换为文本的核心转录引擎。

  • FFMPEG:窃窃私语需要打开,转换和处理音频和视频文件。

  • Python 3.10或更高版本:编程语言窃窃私语是写入的。

  • 自制:一个包装管理器,可以轻松安装Whisper,FFMPEG和Python。

要成功运行这些工具,您将需要:

  • MAC运行MacOS蒙特雷12.3或更高版本:最好在苹果硅芯片上使用MacOS红杉15或更高版本,以更快的性能。

  • 至少8 GB RAM和一些免费的磁盘空间:较大的耳语模型可以使用大量内存(尤其是在长文件上),但是较小的型号在大多数设置上都可以正常工作。

  • 终端应用程序:预装在MacOS上 - 您将使用它输入设置和转录命令。

在macos上窃窃私语

请按照以下步骤安装所需的所有步骤并开始转录文件。如果您已经安装了自制,Python和FFMPEG,那么仍然值得检查这些步骤,以确保所有内容都是最新的。

Mac上的开放终端

终端是MACOS中内置的命令行应用程序 - 这是您将如何安装和运行耳语的方式。您不需要知道如何编码,只需如何粘贴命令即可。要打开终端,请按命令 +空间,键入“终端”,然后命中返回。您还可以在应用程序目录中的“实用程序”文件夹或启动板中的其他文件夹中找到它。

安装或更新自制

Homebrew是MacOS的软件包管理器,例如App Store,但用于强大的命令行工具。它可以轻松安装幕后窃窃私语所需的一切。

如果您没有安装自制型,请粘贴此命令,然后按返回:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

这个命令看起来很吓人,但这就是这一切的含义:

  • /bin/bash是MacOS上Bash Shell二进制的路径。

  • -c告诉您的Mac在Bash Shell中运行以下命令(作为字符串提供)。

  • 报价的一部分 - "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"- 用途curl(一种从Internet获取数据的命令行工具)从GitHub下载Homebrowrew的官方安装程序脚本。

  • 这些标志的意思是:

    • -f=在服务器错误上默默失败。这样可以防止处理不完整或损坏的下载。

    • -s=静默运行。这抑制了进度输出和错误消息。

    • -S=如果发生任何情况,请显示错误。与此一起使用时,仅显示错误消息-s,如果出现问题,允许静音模式仍然报告问题。

    • -L=自动关注重定向。这对于处理URL重定向非常重要,这在从GitHub下载时很常见。

这个单线仪下载了Github的官方Homebrew install脚本,将其直接使用到Bash Shell中-c并执行它自动安装自动安装。

如果已经安装了自制的,请通过运行来更新:

brew update

安装Python 3.10(或更新)

Python是编程语言窃窃私语。苹果在MacOS上包含一个较旧的版本,但是Whisper需要一个更新的版本才能正确运行。 Homebrew使安装正确的版本变得容易。

耳语需要Python 3.10或更高。安装它:

brew install python

如果您已经安装了Python,但不确定是否正确的版本,请检查以下内容:

python3 --version

如果超过3.10,则可以通过以下方式进行升级:

brew upgrade python

一旦进入Python 3.10或更新,就可以去。

安装FFMPEG

FFMPEG是处理音频和视频文件的工具。它有助于低声处理各种媒体格式,例如MP3,MP4,M4A和WAV。没有FFMPEG,Whisper将无法读取或转换您的文件。

使用Homebrew安装它:

brew install ffmpeg

如果您已经安装了FFMPEG,请确保它是最新的:

brew upgrade ffmpeg

您可以通过运行来验证FFMPEG正在工作:

ffmpeg -version

如果它打印了版本信息,那就很好。

通过PIP安装耳语

PIP是Python的内置软件包管理器 - 这是您如何安装Whisper之类的Python应用程序的方式。您将使用PIP直接从OpenAI的GitHub存储库中下载和安装Whisper。

首先,确保PIP是最新的:

pip3 install --upgrade pip

然后安装耳语:

pip3 install git+https://github.com/openai/whisper.git

用耳语进行转录

安装了耳语后,您可以使用单个命令转录音频和视频文件(MP3,MP4,M4A,WAV等)。它支持一系列审慎的型号,从轻巧,快速到大型,高度准确。

音频文件的转录速度比视频文件快得多,因此您可能需要从视频中提取音频,然后用窃窃私语使用该音频,尤其是在使用较大型号时。在Mac上,您可以使用QuickTime Player快速从视频文件中导出音频。

基本用法(自动检测语言)

--model tiny选项运行最快并使用最少的内存,而--model large选项提供最佳准确性,但需要更大的RAM,并且需要更长的时间来处理。

whisper your_file.mp4 --model tiny
whisper your_file.mp4 --model base
whisper your_file.mp4 --model small
whisper your_file.mp4 --model medium
whisper your_file.mp4 --model large

指定语言以获得更快,更准确的结果

如果您知道您的文件是英文的,则可以使用--language en或者--language English

whisper your_file.mp4 --language English --model tiny
whisper your_file.mp4 --language English --model base
whisper your_file.mp4 --language English --model small
whisper your_file.mp4 --language English --model medium
whisper your_file.mp4 --language English --model large

使用上面的一个命令时,输出将直接在同一终端窗口中打印。

但是,Whisper可以创建.txt(Plain Transcript),.srt(大多数视频播放器和编辑者使用的标准字幕格式)和.vtt(Web视频文本跟踪用于HTML5视频,YouTube等的格式,与原始媒体文件相同的目录中的转录文件。如果需要,请添加标志--output_format txt(指定特定格式)或--task translate(这会自动将外语翻译成英语)。

例如,以下内容以英语转录文件,并将其输出到同一目录中的.txt文档。

whisper your_file.mp4 --language en --model small --output_format txt

要用英语生成外语视频的字幕,以下命令将与您的视频或音频文件同一文件夹中生成.txt,.srt和.vtt转录文件。

whisper your_file.mp4 --task translate --model medium

只需要字幕文件(例如.srt)而不是纯文本成绩单?跑步:

whisper your_file.mp4 --language en --task translate --output_format srt

查看所有可用选项:

whisper --help

最后的想法

终端中的耳语不仅是一种转录工具 - 它是创作者,记者,学生和任何处理口语内容的秘密武器。设置过程可能是第一次感觉有些技术,但是一旦启动并运行,它就非常易于使用。

也就是说,低语模型在本地运行,并且取决于Mac的硬件。如果您使用大文件并希望更快的结果,请坚持使用小型或基本型号。如果您需要更高的精度,并且不介意额外的处理时间,请选择中等或大。

耳语论点和选项的完整列表

如果您想探索耳语可以做的一切,包括输出格式,语言支持和高级标志 - 您可以运行whisper --help在终端。这是可用选项的完整列表供快速参考:

usage: whisper [-h] [--model MODEL] [--model_dir MODEL_DIR] [--device DEVICE]
               [--output_dir OUTPUT_DIR]
               [--output_format {txt,vtt,srt,tsv,json,all}]
               [--verbose VERBOSE] [--task {transcribe,translate}]
               [--language {af,am,ar,as,az,ba,be,bg,bn,bo,br,bs,ca,cs,cy,da,de,el,en,es,et,eu,fa,fi,fo,fr,gl,gu,ha,haw,he,hi,hr,ht,hu,hy,id,is,it,ja,jw,ka,kk,km,kn,ko,la,lb,ln,lo,lt,lv,mg,mi,mk,ml,mn,mr,ms,mt,my,ne,nl,nn,no,oc,pa,pl,ps,pt,ro,ru,sa,sd,si,sk,sl,sn,so,sq,sr,su,sv,sw,ta,te,tg,th,tk,tl,tr,tt,uk,ur,uz,vi,yi,yo,yue,zh,Afrikaans,Albanian,Amharic,Arabic,Armenian,Assamese,Azerbaijani,Bashkir,Basque,Belarusian,Bengali,Bosnian,Breton,Bulgarian,Burmese,Cantonese,Castilian,Catalan,Chinese,Croatian,Czech,Danish,Dutch,English,Estonian,Faroese,Finnish,Flemish,French,Galician,Georgian,German,Greek,Gujarati,Haitian,Haitian Creole,Hausa,Hawaiian,Hebrew,Hindi,Hungarian,Icelandic,Indonesian,Italian,Japanese,Javanese,Kannada,Kazakh,Khmer,Korean,Lao,Latin,Latvian,Letzeburgesch,Lingala,Lithuanian,Luxembourgish,Macedonian,Malagasy,Malay,Malayalam,Maltese,Mandarin,Maori,Marathi,Moldavian,Moldovan,Mongolian,Myanmar,Nepali,Norwegian,Nynorsk,Occitan,Panjabi,Pashto,Persian,Polish,Portuguese,Punjabi,Pushto,Romanian,Russian,Sanskrit,Serbian,Shona,Sindhi,Sinhala,Sinhalese,Slovak,Slovenian,Somali,Spanish,Sundanese,Swahili,Swedish,Tagalog,Tajik,Tamil,Tatar,Telugu,Thai,Tibetan,Turkish,Turkmen,Ukrainian,Urdu,Uzbek,Valencian,Vietnamese,Welsh,Yiddish,Yoruba}]
               [--temperature TEMPERATURE] [--best_of BEST_OF]
               [--beam_size BEAM_SIZE] [--patience PATIENCE]
               [--length_penalty LENGTH_PENALTY]
               [--suppress_tokens SUPPRESS_TOKENS]
               [--initial_prompt INITIAL_PROMPT]
               [--condition_on_previous_text CONDITION_ON_PREVIOUS_TEXT]
               [--fp16 FP16]
               [--temperature_increment_on_fallback TEMPERATURE_INCREMENT_ON_FALLBACK]
               [--compression_ratio_threshold COMPRESSION_RATIO_THRESHOLD]
               [--logprob_threshold LOGPROB_THRESHOLD]
               [--no_speech_threshold NO_SPEECH_THRESHOLD]
               [--word_timestamps WORD_TIMESTAMPS]
               [--prepend_punctuations PREPEND_PUNCTUATIONS]
               [--append_punctuations APPEND_PUNCTUATIONS]
               [--highlight_words HIGHLIGHT_WORDS]
               [--max_line_width MAX_LINE_WIDTH]
               [--max_line_count MAX_LINE_COUNT]
               [--max_words_per_line MAX_WORDS_PER_LINE] [--threads THREADS]
               [--clip_timestamps CLIP_TIMESTAMPS]
               [--hallucination_silence_threshold HALLUCINATION_SILENCE_THRESHOLD]
               audio 

positional arguments:
  audio                 audio file(s) to transcribe

options:
  -h, --help            show this help message and exit
  --model MODEL         name of the Whisper model to use (default: turbo)
  --model_dir MODEL_DIR
                        the path to save model files; uses ~/.cache/whisper by
                        default (default: None)
  --device DEVICE       device to use for PyTorch inference (default: cpu)
  --output_dir OUTPUT_DIR, -o OUTPUT_DIR
                        directory to save the outputs (default: .)
  --output_format {txt,vtt,srt,tsv,json,all}, -f {txt,vtt,srt,tsv,json,all}
                        format of the output file; if not specified, all
                        available formats will be produced (default: all)
  --verbose VERBOSE     whether to print out the progress and debug messages
                        (default: True)
  --task {transcribe,translate}
                        whether to perform X->X speech recognition
                        ('transcribe') or X->English translation ('translate')
                        (default: transcribe)
  --language {af,am,ar,as,az,ba,be,bg,bn,bo,br,bs,ca,cs,cy,da,de,el,en,es,et,eu,fa,fi,fo,fr,gl,gu,ha,haw,he,hi,hr,ht,hu,hy,id,is,it,ja,jw,ka,kk,km,kn,ko,la,lb,ln,lo,lt,lv,mg,mi,mk,ml,mn,mr,ms,mt,my,ne,nl,nn,no,oc,pa,pl,ps,pt,ro,ru,sa,sd,si,sk,sl,sn,so,sq,sr,su,sv,sw,ta,te,tg,th,tk,tl,tr,tt,uk,ur,uz,vi,yi,yo,yue,zh,Afrikaans,Albanian,Amharic,Arabic,Armenian,Assamese,Azerbaijani,Bashkir,Basque,Belarusian,Bengali,Bosnian,Breton,Bulgarian,Burmese,Cantonese,Castilian,Catalan,Chinese,Croatian,Czech,Danish,Dutch,English,Estonian,Faroese,Finnish,Flemish,French,Galician,Georgian,German,Greek,Gujarati,Haitian,Haitian Creole,Hausa,Hawaiian,Hebrew,Hindi,Hungarian,Icelandic,Indonesian,Italian,Japanese,Javanese,Kannada,Kazakh,Khmer,Korean,Lao,Latin,Latvian,Letzeburgesch,Lingala,Lithuanian,Luxembourgish,Macedonian,Malagasy,Malay,Malayalam,Maltese,Mandarin,Maori,Marathi,Moldavian,Moldovan,Mongolian,Myanmar,Nepali,Norwegian,Nynorsk,Occitan,Panjabi,Pashto,Persian,Polish,Portuguese,Punjabi,Pushto,Romanian,Russian,Sanskrit,Serbian,Shona,Sindhi,Sinhala,Sinhalese,Slovak,Slovenian,Somali,Spanish,Sundanese,Swahili,Swedish,Tagalog,Tajik,Tamil,Tatar,Telugu,Thai,Tibetan,Turkish,Turkmen,Ukrainian,Urdu,Uzbek,Valencian,Vietnamese,Welsh,Yiddish,Yoruba}
                        language spoken in the audio, specify None to perform
                        language detection (default: None)
  --temperature TEMPERATURE
                        temperature to use for sampling (default: 0)
  --best_of BEST_OF     number of candidates when sampling with non-zero
                        temperature (default: 5)
  --beam_size BEAM_SIZE
                        number of beams in beam search, only applicable when
                        temperature is zero (default: 5)
  --patience PATIENCE   optional patience value to use in beam decoding, as in
                        https://arxiv.org/abs/2204.05424, the default (1.0) is
                        equivalent to conventional beam search (default: None)
  --length_penalty LENGTH_PENALTY
                        optional token length penalty coefficient (alpha) as
                        in https://arxiv.org/abs/1609.08144, uses simple
                        length normalization by default (default: None)
  --suppress_tokens SUPPRESS_TOKENS
                        comma-separated list of token ids to suppress during
                        sampling; '-1' will suppress most special characters
                        except common punctuations (default: -1)
  --initial_prompt INITIAL_PROMPT
                        optional text to provide as a prompt for the first
                        window. (default: None)
  --condition_on_previous_text CONDITION_ON_PREVIOUS_TEXT
                        if True, provide the previous output of the model as a
                        prompt for the next window; disabling may make the
                        text inconsistent across windows, but the model
                        becomes less prone to getting stuck in a failure loop
                        (default: True)
  --fp16 FP16           whether to perform inference in fp16; True by default
                        (default: True)
  --temperature_increment_on_fallback TEMPERATURE_INCREMENT_ON_FALLBACK
                        temperature to increase when falling back when the
                        decoding fails to meet either of the thresholds below
                        (default: 0.2)
  --compression_ratio_threshold COMPRESSION_RATIO_THRESHOLD
                        if the gzip compression ratio is higher than this
                        value, treat the decoding as failed (default: 2.4)
  --logprob_threshold LOGPROB_THRESHOLD
                        if the average log probability is lower than this
                        value, treat the decoding as failed (default: -1.0)
  --no_speech_threshold NO_SPEECH_THRESHOLD
                        if the probability of the <|nospeech|> token is higher
                        than this value AND the decoding has failed due to
                        `logprob_threshold`, consider the segment as silence
                        (default: 0.6)
  --word_timestamps WORD_TIMESTAMPS
                        (experimental) extract word-level timestamps and
                        refine the results based on them (default: False)
  --prepend_punctuations PREPEND_PUNCTUATIONS
                        if word_timestamps is True, merge these punctuation
                        symbols with the next word (default: "'“¿([{-)
  --append_punctuations APPEND_PUNCTUATIONS
                        if word_timestamps is True, merge these punctuation
                        symbols with the previous word (default:
                        "'.。,,!!??::”)]}、)
  --highlight_words HIGHLIGHT_WORDS
                        (requires --word_timestamps True) underline each word
                        as it is spoken in srt and vtt (default: False)
  --max_line_width MAX_LINE_WIDTH
                        (requires --word_timestamps True) the maximum number
                        of characters in a line before breaking the line
                        (default: None)
  --max_line_count MAX_LINE_COUNT
                        (requires --word_timestamps True) the maximum number
                        of lines in a segment (default: None)
  --max_words_per_line MAX_WORDS_PER_LINE
                        (requires --word_timestamps True, no effect with
                        --max_line_width) the maximum number of words in a
                        segment (default: None)
  --threads THREADS     number of threads used by torch for CPU inference;
                        supercedes MKL_NUM_THREADS/OMP_NUM_THREADS (default:
                        0)
  --clip_timestamps CLIP_TIMESTAMPS
                        comma-separated list start,end,start,end,...
                        timestamps (in seconds) of clips to process, where the
                        last end timestamp defaults to the end of the file
                        (default: 0)
  --hallucination_silence_threshold HALLUCINATION_SILENCE_THRESHOLD
                        (requires --word_timestamps True) skip silent periods
                        longer than this threshold (in seconds) when a
                        possible hallucination is detected (default: None)

不要错过:如何在MacOS上的文件中删除或添加“从哪里”元数据

封面照片,屏幕截图和gifs by shutterstock。