You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在RStudio中调用whisper-standalone-win时出现Unicode编码错误

解决RStudio中调用whisper-faster.exe的Unicode编码问题

针对Windows 10下RStudio调用whisper-standalone-win出现的Unicode编码错误,可尝试以下几种方案:

1. 强制在UTF-8编码环境下调用程序

通过cmd /c先切换cmd的编码为UTF-8(代码页65001),再执行程序,确保输出编码和RStudio兼容:

# 直接执行查看帮助(程序在RStudio工作目录时)
shell('cmd /c "chcp 65001 && whisper-faster.exe --help"')

# 程序不在当前工作目录时,使用完整路径
shell('cmd /c "chcp 65001 && C:\\your\\full\\path\\to\\whisper-faster.exe --help"')

2. 捕获输出时指定编码

如果需要捕获程序输出并在R中处理,结合intern=TRUE和编码参数:

# 捕获输出并指定UTF-8编码
output <- shell('cmd /c "chcp 65001 && whisper-faster.exe --help"', intern = TRUE, encoding = "UTF-8")
# 打印时保持编码格式
print(output, encoding = "UTF-8")

3. 修改RStudio全局编码设置

调整RStudio的默认编码为UTF-8,确保控制台和文件读写的编码一致:

  • 打开RStudio,依次点击 Tools -> Global Options -> Code -> Saving
  • 将Default text encoding设置为UTF-8
  • 重启RStudio后再尝试调用程序

4. 使用system2通过文件捕获输出

通过将程序的标准输出/错误写入文件,再读取文件时指定编码,避免直接输出的编码冲突:

# 执行程序并将输出写入文件
system2(
  command = "whisper-faster.exe",
  args = c("--help"),
  stdout = "whisper_output.txt",
  stderr = "whisper_error.txt",
  shell = TRUE
)

# 读取输出文件,指定UTF-8编码
output_lines <- readLines("whisper_output.txt", encoding = "UTF-8")
print(output_lines)

5. 临时设置R的本地编码环境

在调用程序前,临时设置R的编码环境变量,配合上述方法使用:

Sys.setenv(LC_ALL = "en_US.UTF-8")
Sys.setenv(LANG = "en_US.UTF-8")
# 再执行程序调用
shell('cmd /c "chcp 65001 && whisper-faster.exe --help"')

内容的提问来源于stack exchange,提问作者lost

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 14:20:28