#6003 Whisper.net recognition failed: Method not found: 'System.TimeSpan System.TimeSpan.FromMilliseconds(Int64)'. at Whispe

240e:39c* Posted at: 1 day ago

Whisper.net recognition failed: Method not found: 'System.TimeSpan System.TimeSpan.FromMilliseconds(Int64)'.
at Whisper.net.WhisperProcessor.OnNewSegment(IntPtr state)
at Whisper.net.WhisperProcessor.OnNewSegmentStatic(IntPtr ctx, IntPtr state, Int32 nNew, IntPtr userData)
at Whisper.net.Internals.Native.Implementations.LibraryImportLibWhisper.whisper_full_with_state(IntPtr context, IntPtr state, WhisperFullParams parameters, IntPtr samples, Int32 nSamples)
at Whisper.net.WhisperProcessor.Process(ReadOnlySpan`1 samples)
at Whisper.net.WhisperProcessor.Process(Single[] samples)
at Whisper.net.WhisperProcessor.Process(Stream waveStream)
at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span`1 copyOfArgs, BindingFlags invokeAttr)
Traceback (most recent call last):
File "H:\pyvideotrans\videotrans\recognition\_wh
......
y", line 205, in run

return _cls(**kwargs).run()  # type:ignore
       ^^^^^^^^^^^^^^^^^^^^

File "H:\pyvideotrans\videotrans\recognition\_base.py", line 92, in run

res = self._exec()
      ^^^^^^^^^^^^

File "H:\pyvideotrans\videotrans\recognition\_whispernet.py", line 285, in _exec

raise SpeechToTextError(f"Whisper.net recognition failed: {str(e)}")

videotrans.configure.excepts.SpeechToTextError: Whisper.net recognition failed: Method not found: 'System.TimeSpan System.TimeSpan.FromMilliseconds(Int64)'.
at Whisper.net.WhisperProcessor.OnNewSegment(IntPtr state)
at Whisper.net.WhisperProcessor.OnNewSegmentStatic(IntPtr ctx, IntPtr state, Int32 nNew, IntPtr userData)
at Whisper.net.Internals.Native.Implementations.LibraryImportLibWhisper.whisper_full_with_state(IntPtr context, IntPtr state, WhisperFullParams parameters, IntPtr samples, Int32 nSamples)
at Whisper.net.WhisperProcessor.Process(ReadOnlySpan`1 samples)
at Whisper.net.WhisperProcessor.Process(Single[] samples)
at Whisper.net.WhisperProcessor.Process(Stream waveStream)
at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span`1 copyOfArgs, BindingFlags invokeAttr)

cfg=[TaskCfgVTT]当前工作模式: 翻译视频或音频 单视频模式
原始输入文件名: G:/1.mp4,
输出结果保存到文件夹: G:/_video_out/1-mp4,
临时文件夹: H:/pyvideotrans/tmp/15508/5c7d88d507
已选 清理已存在
未选 启用CUDA加速
未选 降噪
已选 识别说话人,最大说话人数量3
语音识别:Whisper.NET, model_name: ggml-large-v3-turbo.bin, 发音语言: 英语, 断句方式:默认断句
翻译渠道:微软(免费),原始语言:英语,目标语言:简体中文, 已选 发送完整字幕
配音渠道:Spark-TTS(本地API), 角色:clone, 配音语言:简体中文, 未选 二次语音识别
音量:+0%, 语速:+0%, 已选 音频加速, 未选 视频慢速
字幕: 嵌入硬字幕
已选 分离人声与背景声,存在分离后的纯净人声文件,存在分离后的背景声音文件
代理地址:


=
system:Windows-10-10.0.26100-SP0
version:v4.06
frozen:False
language:zh
root_dir:H:/pyvideotrans
Python: 3.11.7 (tags/v3.11.7:fa7a6f2, Dec 4 2023, 19:24:49) [MSC v.1937 64 bit (AMD64)]

3 Replies

Whisper.net 报错 Method not found: 'System.TimeSpan System.TimeSpan.FromMilliseconds(Int64)' 是由于 .NET 运行时版本不兼容所致。Whisper.net 依赖 .NET 6.0 或更高版本的运行时,而当前环境可能缺失或版本过低。

解决步骤:

  1. 安装 .NET 6.0 或更高版本
    前往 https://dotnet.microsoft.com/en-us/download/dotnet/6.0 下载并安装 .NET SDK 6.0 或 .NET Runtime 6.0(建议安装 SDK)。
  2. 确保通过 uv sync --extra dotnet 安装了 pythonnet
    在源码目录下执行:

    uv sync --extra dotnet

    该命令会安装 pythonnet>=3.0.1 及其关联的 .NET 绑定。

  3. 确认 .NET 运行时版本
    在命令行运行 dotnet --info,确认 .NET 版本 ≥ 6.0。
  4. 重启源码环境并重试
    运行 uv run sp.py 再次启动软件。

若问题依旧,请删除 models/ 目录下的 ggml 模型文件,重新下载(确保为 .bin 格式并放回 models/),然后重试。

针对问题1.我安装了 Microsoft Windows Desktop Runtime - 6.0.36 (x64)6.0.36.34217
Microsoft Windows Desktop Runtime - 8.0.29 (x64)8.0.29.36225 两个版本
2.我运行uv sync --extra dotnet的结果如下:PS H:\pyvideotrans> uv sync --extra dotnet
Resolved 402 packages in 25ms
× Failed to build pynini==2.1.6.post1
├─▶ The build backend returned an error
╰─▶ Call to setuptools.build_meta:__legacy__.build_wheel failed (exit code: 1)

  [stdout]
  running bdist_wheel
  running build
  running build_py
  copying pynini\__init__.py -> build\lib.win-amd64-cpython-310\pynini
  copying pywrapfst\__init__.py -> build\lib.win-amd64-cpython-310\pywrapfst
  copying pynini\examples\case.py -> build\lib.win-amd64-cpython-310\pynini\examples
  copying pynini\examples\chatspeak.py -> build\lib.win-amd64-cpython-310\pynini\examples
  copying pynini\examples\chatspeak_model.py -> build\lib.win-amd64-cpython-310\pynini\examples
  copying pynini\examples

......
65:

  SetuptoolsDeprecationWarning: License classifiers are deprecated.
  !!

          ********************************************************************************
          Please consider removing the following classifiers in favor of a SPDX license expression:

          License :: OSI Approved :: Apache Software License

          See https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#license for details.
          ********************************************************************************

  !!
    self._finalize_license_expression()
  cl: ������ error D8021 :��Ч����ֵ������/Wno-register��
  error: command 'C:\\Program Files (x86)\\Microsoft Visual
  Studio\\2022\\BuildTools\\VC\\Tools\\MSVC\\14.44.35207\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2

  hint: This usually indicates a problem with the package or the build environment.

help: pynini (v2.1.6.post1) was included because pyvideotrans (v4.5) depends on wetextprocessing (v1.2.0)

    which depends on `pynini`无法确认pythonnet>=3.0.1 及其关联的 .NET 绑定是否成功

3PS H:\pyvideotrans> dotnet --info

Host:
Version: 8.0.29
Architecture: x64
Commit: 18fd75c847
RID: win-x64

.NET SDKs installed:
No SDKs were found.

.NET runtimes installed:
Microsoft.NETCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.29 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.29 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
None

Environment variables:
DOTNET_ROOT [C:\Program Files\dotnet]

global.json file:
Not found

Learn more:
https://aka.ms/dotnet/info

Download .NET:
https://aka.ms/dotnet/download显示两个版本的.net均大于6.0

问题根源在于 .NET 运行时版本不完整(只有 Runtime 没有 SDK),以及 pynini 编译失败导致 uv sync --extra dotnet 没有成功安装完整的 .NET 绑定。Whisper.net 需要 .NET SDK 才能正常工作。

解决方案(按优先级推荐)

方案 1:安装 .NET SDK 8.0(最简单有效)

  • 前往 .NET SDK 8.0 下载页面 下载并安装 SDK 8.0.xxx(并非仅 Runtime)。
  • 安装后重启终端,运行 dotnet --info 确认显示 "SDK" 版本。
  • 重新执行 uv sync --extra dotnet(如果仍失败,参考下方“编译环境修复”)。

方案 2:临时跳过 pynini 编译,单独安装 pythonnet

  • 如果只是为了使用 Whisper.net,pythonnet 是必须的,而 pyniniwettextprocessing 的依赖,并非 Whisper.net 直接依赖。
  • 在源码目录下执行:

    uv add pythonnet>=3.0.1
  • 这会单独安装 pythonnet,跳过 pynini 的编译。之后测试 Whisper.net 是否正常。
  • 如果该命令也失败,则需先安装 Visual Studio 编译工具(见下方)。

方案 3:安装 Visual Studio 编译工具以修复 pynini 编译

验证操作

  • 重启源码环境:uv run sp.py
  • 在语音识别渠道中重新选择 “Whisper.NET” 并尝试运行。

如果问题依然存在,请提供 uv run sp.py 启动后的控制台日志(尤其是关于 pythonnetWhisper.net 的初始化信息)以及 uv list | findstr pythonnet 的输出,以便进一步分析。

Post Your Reply
Open source and free maintenance is not easy. If this project is helpful to you, please consider making a small donation to help the project continue to maintain and update.

Dondate via ko-fi.com

Dondate via PayPal

Related resource