亲爱的小朋友们,大家好!欢迎来到有趣的语音识别大冒险!今天,我们将一起探索神奇的语音识别世界,就像是魔法一样,让机器能听懂我们说的话。
想象一下,如果我们可以和电脑、手机甚至玩具交流,它们听得懂我们说的话,那会是多么有趣呢?就像是跟朋友聊天一样,我们可以通过声音传达我们的想法和感受。那么,有没有想过这是怎么做到的呢?
就像小朋友们在学习说话一样,计算机也需要学习才能听懂我们的话。它们使用了一种叫做“语音识别大模型”的魔法工具。这个大模型可以理解各种各样的声音,就像是小朋友们可以听懂不同的朋友说的话一样。
在我们的大冒险中,我们会了解这个神奇的大模型是怎么工作的,它是如何通过分析声音的特点来判断我们说的是什么。就像侦探一样,它会仔细聆听每一个音频,然后猜猜我们在说什么呢?
让我们一起探索语音识别的奥秘,一起学习怎么与计算机交流,让声音成为我们沟通的桥梁。准备好了吗?让我们开始这场有趣的冒险吧!
大冒险开始啦!
本次实验用到的环境与是 Colab 相同。没用过的小朋友可以翻看前面的 手把手教你部署开源可商用GPT - Llama2 文章准备实验环境以及使用方法。
一、进入实验环境
打开 Colab 网址
https://colab.research.google.com/
二、新建笔记本,执行以下命令进行环境检查
!nvidia-smi -L
!nvidia-smi
两条命令解释:
!nvidia-smi -L:-L 参数用于列出系统上安装的所有 NVIDIA GPU 设备。运行此命令后,您将看到关于可用 GPU 的信息,包括其型号和 UUID。
!nvidia-smi:不带任何参数运行 nvidia-smi 会显示有关 NVIDIA GPU 的详细信息,包括:
没开始使用GPU时,nvidia-smi命令返回的结果是空的(No running processes found)。
三、安装 Whisper
!pip install requests beautifulsoup4
!pip install git+https://github.com/openai/whisper.git
import torch
import sys
device = torch.device('cuda:0')
print('正在使用的设备:', device, file=sys.stderr)
print('Whisper已经被安装请执行下一个单元')
四、模型选择
这里选择的是 large-v2模型,也可以选择下面这些:tiny.en, tiny, base.en, base, small.en, small, medium.en, medium, large, large-v2
#@markdown # ** whisper Model选择**
Model = 'large-v2' #@param ['tiny.en', 'tiny', 'base.en', 'base', 'small.en', 'small', 'medium.en', 'medium', 'large', 'large-v2']
import whisper
from IPython.display import Markdown
whisper_model = whisper.load_model(Model)
if Model in whisper.available_models():
display(Markdown(
f"**{Model} model is selected.**"
))
else:
display(Markdown(
f"**{Model} model is no longer available.** Please select one of the following: - {' - '.join(whisper.available_models())}"
))
五、上传音频文件
1、首先创建音频文件夹
创建方式如下图:
2、上传音频文件
直接将音频文件,拖拽到刚创建的 upload 文件夹中。
六、开始运行模型
#@markdown # **开始运行model 设置相关参数** 🚀
language = "zh" ## 这里直接写死为中文的
verbose = 'Live transcription' #@param ['Live transcription', 'Progress bar', 'None']
task = 'transcribe' #@param ['transcribe', 'translate']
temperature = 0.2 #@param {type:"slider", min:0, max:1, step:0.05}
temperature_increment_on_fallback = 0.2 #@param {type:"slider", min:0, max:1, step:0.05}
best_of = 5 #@param {type:"integer"}
beam_size = 8 #@param {type:"integer"}
patience = 1.0 #@param {type:"number"}
length_penalty = -0.05 #@param {type:"slider", min:-0.05, max:1, step:0.05}
suppress_tokens = "-1" #@param {type:"string"}
initial_prompt = "" #@param {type:"string"}
condition_on_previous_text = True #@param {type:"boolean"}
fp16 = True #@param {type:"boolean"}
compression_ratio_threshold = 2.4 #@param {type:"number"}
logprob_threshold = -1.0 #@param {type:"number"}
no_speech_threshold = 0.6 #@param {type:"slider", min:-0.0, max:1, step:0.05}
verbose_lut = {
'Live transcription': True,
'Progress bar': False,
'None': None
}
import numpy as np
import warnings
import shutil
from pathlib import Path
args = dict(
language = (None if language == "Auto detection" else language),
verbose = verbose_lut[verbose],
task = task,
temperature = temperature,
temperature_increment_on_fallback = temperature_increment_on_fallback,
best_of = best_of,
beam_size = beam_size,
patience=patience,
length_penalty=(length_penalty if length_penalty>=0.0 else None),
suppress_tokens=suppress_tokens,
initial_prompt=(None if not initial_prompt else initial_prompt),
condition_on_previous_text=condition_on_previous_text,
fp16=fp16,
compression_ratio_threshold=compression_ratio_threshold,
logprob_threshold=logprob_threshold,
no_speech_threshold=no_speech_threshold
)
temperature = args.pop("temperature")
temperature_increment_on_fallback = args.pop("temperature_increment_on_fallback")
if temperature_increment_on_fallback is not None:
temperature = tuple(np.arange(temperature, 1.0 + 1e-6, temperature_increment_on_fallback))
else:
temperature = [temperature]
if Model.endswith(".en") and args["language"] not in {"en", "English"}:
warnings.warn(f"{Model} is an English-only model but receipted '{args['language']}'; using English instead.")
args["language"] = "en"
title ="test1"
audio_path = "/content/upload/Whisper.mp3"
audio_path_local = Path(audio_path).resolve()
print("audio local path:", audio_path_local)
print("audio audio_path:", audio_path)
transcription = whisper.transcribe(
whisper_model,
str(audio_path_local),
temperature=temperature,
**args,
)
运行结果如下图,我们可以看到 Whisper 语音模型非常准确的识别出了我们的语音内容。
你是否心动了呢,赶快开始你的语音识别之旅吧!
Whisper是一种基于深度学习的语音识别模型,它是一种通用的语音识别模型,可以用于语音识别、语音翻译和语言识别等任务。它是通过收集来自多个数据源的多语言、多任务的数据进行训练的。这些数据包含了各种语言和口音的语音样本,以及各种不同的环境噪声和干扰。模型使用了一种称为“自注意力机制”的技术,它可以在处理不同的语音信号时,更好地捕捉到语音中的关键信息。此外,还使用了一种称为“注意力机制”的技术,它可以在处理不同的语音信号时,更好地捕捉到语音中的关键信息。模型的训练过程非常复杂,需要大量的计算资源和时间。但是,一旦训练完成,模型可以在各种不同的应用场景中提供高质量的语音识别结果。