Whisper.rn 项目使用教程
1. 项目介绍
Whisper.rn 是一个 React Native 绑定库,用于集成 OpenAI 的 Whisper 自动语音识别(ASR)模型。Whisper 是一个高性能的语音识别系统,经过大量多语言和多任务监督数据的训练,能够处理多种语言并将其翻译成英语。Whisper.rn 使得开发者可以在 React Native 应用中轻松实现语音转文本功能。
2. 项目快速启动
安装依赖
首先,确保你已经安装了 Node.js 和 npm。然后,在你的 React Native 项目中安装 whisper.rn:
npm install whisper.rn
iOS 配置
在 iOS 项目中,重新运行 pod-install:
npx pod-install
如果你打算使用中等或大型模型,建议在 iOS 项目中启用“扩展虚拟地址”功能。
Android 配置
在 Android 项目中,如果启用了 ProGuard,请添加以下规则:
# whisper.rn
-keep class com.rnwhisper.** { *; }
建议在项目根目录的构建配置中使用 ndkVersion = "24.0.8215888" 或更高版本。
添加麦克风权限
iOS
在 ios/[YOUR_APP_NAME]/info.plist 中添加以下内容:
<key>NSMicrophoneUsageDescription</key>
<string>This app requires microphone access in order to transcribe speech</string>
Android
在 android/app/src/main/AndroidManifest.xml 中添加以下内容:
<uses-permission android:name="android.permission.RECORD_AUDIO" />
使用示例
以下是一个简单的使用示例,展示如何初始化 Whisper 并进行语音转文本:
import { initWhisper } from 'whisper.rn';
const whisperContext = await initWhisper({
filePath: 'file:///path/to/ggml-tiny.en.bin',
});
const sampleFilePath = 'file:///path/to/sample.wav';
const options = { language: 'en' };
const [stop, promise] = whisperContext.transcribe(sampleFilePath, options);
const [result] = await promise;
console.log(result); // 输出语音转文本的结果
3. 应用案例和最佳实践
实时语音转文本
Whisper.rn 支持实时语音转文本功能。以下是一个实时语音转文本的示例:
const [stop, subscribe] = await whisperContext.transcribeRealtime(options);
subscribe(evt => {
const [isCapturing, data, processTime, recordingTime] = evt;
console.log(`Realtime transcribing: ${isCapturing ? 'ON' : 'OFF'}\n` +
`Result: ${data.result}\n\n` +
`Process time: ${processTime}ms\n` +
`Recording time: ${recordingTime}ms`);
if (!isCapturing) {
console.log('Finished realtime transcribing');
}
});
使用 Core ML 模型
在 iOS 上,你可以使用 Core ML 模型来提高性能。以下是如何使用 Core ML 模型的示例:
import { Platform } from 'react-native';
const whisperContext = await initWhisper({
filePath: require('./assets/ggml-tiny.en.bin'),
coreMLModelAsset: Platform.OS === 'ios' ? {
filename: 'ggml-tiny.en-encoder.mlmodelc',
assets: [
require('./assets/ggml-tiny.en-encoder.mlmodelc/weights/weight.bin'),
require('./assets/ggml-tiny.en-encoder.mlmodelc/model.mil'),
require('./assets/ggml-tiny.en-encoder.mlmodelc/coremldata.bin'),
],
} : undefined,
});
4. 典型生态项目
1. Expo 项目
如果你使用 Expo,你需要在项目中预构建 Whisper.rn。请参考 Expo 的指南进行配置。
2. 使用 FFmpeg 进行音频处理
在某些情况下,你可能需要使用 FFmpeg 对音频文件进行预处理。你可以使用 ffmpeg-kit-react-native 库来实现这一点。
3. 使用 React Native 状态管理
在复杂的应用中,你可能需要使用状态管理库(如 Redux 或 MobX)来管理 Whisper 的上下文和状态。
通过以上步骤,你可以在 React Native 项目中成功集成 Whisper.rn,并实现语音转文本功能。
Kimi-K2.5Kimi K2.5 是一款开源的原生多模态智能体模型,它在 Kimi-K2-Base 的基础上,通过对约 15 万亿混合视觉和文本 tokens 进行持续预训练构建而成。该模型将视觉与语言理解、高级智能体能力、即时模式与思考模式,以及对话式与智能体范式无缝融合。Python00
GLM-4.7-FlashGLM-4.7-Flash 是一款 30B-A3B MoE 模型。作为 30B 级别中的佼佼者,GLM-4.7-Flash 为追求性能与效率平衡的轻量化部署提供了全新选择。Jinja00
VLOOKVLOOK™ 是优雅好用的 Typora/Markdown 主题包和增强插件。 VLOOK™ is an elegant and practical THEME PACKAGE × ENHANCEMENT PLUGIN for Typora/Markdown.Less00
PaddleOCR-VL-1.5PaddleOCR-VL-1.5 是 PaddleOCR-VL 的新一代进阶模型,在 OmniDocBench v1.5 上实现了 94.5% 的全新 state-of-the-art 准确率。 为了严格评估模型在真实物理畸变下的鲁棒性——包括扫描伪影、倾斜、扭曲、屏幕拍摄和光照变化——我们提出了 Real5-OmniDocBench 基准测试集。实验结果表明,该增强模型在新构建的基准测试集上达到了 SOTA 性能。此外,我们通过整合印章识别和文本检测识别(text spotting)任务扩展了模型的能力,同时保持 0.9B 的超紧凑 VLM 规模,具备高效率特性。Python00
KuiklyUI基于KMP技术的高性能、全平台开发框架,具备统一代码库、极致易用性和动态灵活性。 Provide a high-performance, full-platform development framework with unified codebase, ultimate ease of use, and dynamic flexibility. 注意:本仓库为Github仓库镜像,PR或Issue请移步至Github发起,感谢支持!Kotlin07
compass-metrics-modelMetrics model project for the OSS CompassPython00