# @chengsokdara/use-whisper 中文文档

规范地址：https://npmcn.com/package/%40chengsokdara/use-whisper/

版本：0\.2\.0
npm 元数据更新时间：2023-03-18T13:14:57.855Z
中文译文更新时间：2026-11-09T12:12:48.107Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40chengsokdara/use-whisper
原文对照：https://npmcn.com/package/%40chengsokdara/use-whisper/?lang=original
项目主页：https://github.com/chengsokdara/use-whisper#readme
源码仓库：https://github.com/chengsokdara/use-whisper

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：32.4 kB，25 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- 运行依赖：6 个
- peer 依赖：react \*
- 首次发布：2023-03-06T21:16:41.760Z
- 最新版本发布：2023-03-18T13:14:57.733Z
- 近 30 天下载量：4427（2026-10-10 至 2026-11-08，npm 官方下载统计）
- 已发布版本数：16（近 12 个月 0 个）

## 中文简介

反应 Hook for OpenAI Whisper API 配有语音录音机并内置去声去声.

## 安装

```sh
npm install @chengsokdara/use-whisper
```

也可以使用：`pnpm add @chengsokdara/use-whisper`、`yarn add @chengsokdara/use-whisper`、`bun add @chengsokdara/use-whisper`

## README

# 使用低声

反应 Hook for OpenAI Whisper API 有语音记录器,实时转录以及内置的静音去除

* * *

-   ### 演示
    
-   ###### 实时复制演示
    

[https://user-images.githubusercontent.com/2707253/224465747-0b1ee159-21dd-4cd0-af9d-6fc9b882d716.mp4 请检查isbn=值 (帮助)](https://user-images.githubusercontent.com/2707253/224465747-0b1ee159-21dd-4cd0-af9d-6fc9b882d716.mp4)

* * *

-   ### 通知
    
    正在开发使用Whisper for React Independent.
    

仓库 : [https://github.com/cungsokdara/use-whiper-native 互联网档案馆的存檔,存档日期2013-12-22](https://github.com/chengsokdara/use-whisper-native)

进展: [https://github.com/cungsokdara/use-whiper-native/issues/1 (中文(简体) )](https://github.com/chengsokdara/use-whisper-native/issues/1)

-   ### 安装
    

```
npm i @chengsokdara/use-whisper
```

```
yarn add @chengsokdara/use-whisper
```

-   ### 使用量
    

```jsx
import { useWhisper } from '@chengsokdara/use-whisper'

const App = () => {
  const {
    recording,
    speaking,
    transcribing,
    transcript,
    pauseRecording,
    startRecording,
    stopRecording,
  } = useWhisper({
    apiKey: process.env.OPENAI_API_TOKEN, // YOUR_OPEN_AI_TOKEN
  })

  return (
    <div>
      <p>Recording: {recording}</p>
      <p>Speaking: {speaking}</p>
      <p>Transcribing: {transcribing}</p>
      <p>Transcribed Text: {transcript.text}</p>
      <button onClick={() => startRecording()}>Start</button>
      <button onClick={() => pauseRecording()}>Pause</button>
      <button onClick={() => stopRecording()}>Stop</button>
    </div>
  )
}
```

-   ###### 自定义服务器( 保留 OpenAI API 令牌安全)
    

```jsx
import { useWhisper } from '@chengsokdara/use-whisper'

const App = () => {
  /**
   * you have more control like this
   * do whatever you want with the recorded speech
   * send it to your own custom server
   * and return the response back to useWhisper
   */
  const onTranscribe = (blob: Blob) => {
    const base64 = await new Promise<string | ArrayBuffer | null>(
      (resolve) => {
        const reader = new FileReader()
        reader.onloadend = () => resolve(reader.result)
        reader.readAsDataURL(blob)
      }
    )
    const body = JSON.stringify({ file: base64, model: 'whisper-1' })
    const headers = { 'Content-Type': 'application/json' }
    const { default: axios } = await import('axios')
    const response = await axios.post('/api/whisper', body, {
      headers,
    })
    const { text } = await response.data
    // you must return result from your server in Transcript format
    return {
      blob,
      text,
    }
  }

  const { transcript } = useWhisper({
    // callback to handle transcription with custom server
    onTranscribe,
  })

  return (
    <div>
      <p>{transcript.text}</p>
    </div>
  )
}
```

-   ### 实例
    
-   ###### 实时流线记录
    

```jsx
import { useWhisper } from '@chengsokdara/use-whisper'

const App = () => {
  const { transcript } = useWhisper({
    apiKey: process.env.OPENAI_API_TOKEN, // YOUR_OPEN_AI_TOKEN
    streaming: true,
    timeSlice: 1_000, // 1 second
    whisperConfig: {
      language: 'en',
    },
  })

  return (
    <div>
      <p>{transcript.text}</p>
    </div>
  )
}
```

-   ###### 在发送到 Whisper 以节省费用之前删除沉默
    

```jsx
import { useWhisper } from '@chengsokdara/use-whisper'

const App = () => {
  const { transcript } = useWhisper({
    apiKey: process.env.OPENAI_API_TOKEN, // YOUR_OPEN_AI_TOKEN
    // use ffmpeg-wasp to remove silence from recorded speech
    removeSilence: true,
  })

  return (
    <div>
      <p>{transcript.text}</p>
    </div>
  )
}
```

-   ###### 在挂载的组件上自动开始记录
    

```jsx
import { useWhisper } from '@chengsokdara/use-whisper'

const App = () => {
  const { transcript } = useWhisper({
    apiKey: process.env.OPENAI_API_TOKEN, // YOUR_OPEN_AI_TOKEN
    // will auto start recording speech upon component mounted
    autoStart: true,
  })

  return (
    <div>
      <p>{transcript.text}</p>
    </div>
  )
}
```

-   ###### 只要用户在说话,就继续录制
    

```jsx
import { useWhisper } from '@chengsokdara/use-whisper'

const App = () => {
  const { transcript } = useWhisper({
    apiKey: process.env.OPENAI_API_TOKEN, // YOUR_OPEN_AI_TOKEN
    nonStop: true, // keep recording as long as the user is speaking
    stopTimeout: 5000, // auto stop after 5 seconds
  })

  return (
    <div>
      <p>{transcript.text}</p>
    </div>
  )
}
```

-   ###### 自定义自定义自定义 API 配置, 当 autoTransis 属实时
    

```jsx
import { useWhisper } from '@chengsokdara/use-whisper'

const App = () => {
  const { transcript } = useWhisper({
    apiKey: process.env.OPENAI_API_TOKEN, // YOUR_OPEN_AI_TOKEN
    autoTranscribe: true,
    whisperConfig: {
      prompt: 'previous conversation', // you can pass previous conversation for context
      response_format: 'text', // output text instead of json
      temperature: 0.8, // random output
      language: 'es', // Spanish
    },
  })

  return (
    <div>
      <p>{transcript.text}</p>
    </div>
  )
}
```

-   ### 依赖关系
    
    -   **@cungsokdara/反应-呼-sync** 同步反应钩
    -   **记录曲c:** 交叉浏览器录音机
    -   **跛脚** 将 wav 编码为 mp3 用于交叉浏览器支持
    -   **@ffmpeg/ffmpeg: (中文(简体) )** 用于消音功能
    -   **汉克:** 用于语音检测
    -   **轴 :** 因为抓取与 Whisper 结束点无关

_这些依赖性大多是懒惰地装入的,所以只有在需要时才导入_

-   ### API 密码
    
-   ###### 配置对象
    

| 名称 | 类型 | 默认值 | 说明 |
| --- | --- | --- | --- |
| 键 | 字符串 | '' | 您的 OpenAI API 令牌 |
| 自动启动 | 布尔 | 虚假 | 在组件挂载上自动启动语音记录 |
| 自动编译 | 布尔 | 真实 | 停止录制后应自动转录 |
| 模式 | 字符串 | 转录 | 控制 Whisper 模式或翻录或翻译,目前只支持向英语翻译 |
| 不停止 | 布尔 | 虚假 | 如果真实, 记录会在停止时自动停止 。 但是,如果用户继续说话,录音机会继续录音 |
| 删除静态 | 布尔 | 虚假 | 在发送文件到 OpenAI API 之前去除沉默 |
| 停止超时 | 编号 | 5 000毫瓦时 | 如果非停止是真实的,则需要这样做。 记录器自动停止时的此控制 |
| 流线 | 布尔 | 虚假 | 基于时间切换的实时语音 |
| 时间 | 编号 | 1,000 毫秒( x) | 数据辅助事件之间的间隔 |
| 微声配置 | [微声阿皮克](https://npmcn.com/package/%40chengsokdara/use-whisper/#readme-whisperapiconfig) | 未定义 | 微声 API 复制配置 |
| 可读数据 | (blob: Blob) 无效 | 未定义 | 获取时间间隔中记录blob的回调功能Slich |
| 打开 | (blob:blob) => 承诺 <[语录](https://npmcn.com/package/%40chengsokdara/use-whisper/#readme-transcript)\> 翻译: | 未定义 | 在自定义服务器上处理转录的调用功能 |

-   ###### 微声阿皮克
    

| 名称 | 类型 | 默认值 | 说明 |
| --- | --- | --- | --- |
| 提示 | 字符串 | 未定义 | 一个可选文本来指导模型的风格或延续之前的音频段. 提示应当与音频语言相匹配. |
| 响应( f) | 字符串 | 乔森 | 笔录输出的格式,在其中一种选项:json,文本,srt,动词-json,或vtt. |
| 温度 | 编号 | 0 个 | 采样温度在0到1之间. 像0.8这样的更高值会使输出更加随机,而像0.2这样的更低值会使它更有重点和决定力. 如果设置为 0, 模型将使用 [日志概率](https://en.wikipedia.org/wiki/Log_probability) 以自动提高温度,直到某些阈值被击中. |
| 语言 | 字符串 | 内 | 输入音频的语言. 提供输入语言 [ISO-639-1号标准](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) 格式将提高准确性和耐久性. |

-   ###### 返回对象
    

| 名称 | 类型 | 说明 |
| --- | --- | --- |
| 录音 | 布尔 | 语音录音状态 |
| 说话 | 布尔 | 检测用户说话时 |
| 转录 | 布尔 | 并同时删除语音中的静音, 并向 OpenAI Whisper API 发送请求 |
| 记录 | [语录](https://npmcn.com/package/%40chengsokdara/use-whisper/#readme-transcript) | 读取完成后返回对象 |
| 暂停记录 | 答应 | 暂停语音录音 |
| 开始记录 | 答应 | 开始语音录音 |
| 停止记录 | 答应 | 停止语音录音 |

-   ###### 语录
    

| 名称 | 类型 | 说明 |
| --- | --- | --- |
| 块 | 块 | 在 JavaScript Blob 中录制的语音 |
| 文本 | 字符串 | 从 Whisper API 返回的转写文本 |

-   ### 路线图
    
    -   反应-内在支持,将导出为 use-whiper/内在

* * *

**_使用 React 或 React Natural 联系我开发网络或移动应用程序_**  
[https://cungsokdara.github.io (英语)](https://chengsokdara.github.io/)

## 常见问题

### @chengsokdara/use-whisper 是什么？

反应 Hook for OpenAI Whisper API 配有语音录音机并内置去声去声\.

### 如何安装 @chengsokdara/use-whisper？

在项目目录运行 npm install @chengsokdara/use-whisper，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：react（\*）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @chengsokdara/use-whisper 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @chengsokdara/use-whisper 支持 ESM 还是 CommonJS？

同时提供 ES Module 与 CommonJS 入口，import 和 require\(\) 都可以使用，打包工具会自动选择合适的版本。

### @chengsokdara/use-whisper 可以商用吗？

@chengsokdara/use-whisper 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @chengsokdara/use-whisper 的下载量有多少？

根据 npm 官方下载统计，@chengsokdara/use-whisper 在 2026/10/10 – 2026/11/08 这 30 天内被下载 4,427 次，日均约 148 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @chengsokdara/use-whisper 还在维护吗？

最新版本 0\.2\.0 发布于 2023/03/18（3 年前）；至今共发布 16 个版本，其中过去 12 个月发布了 0 个；首次发布于 2023/03/07。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

