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

240e:39c* Posted at: 5 hours 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 "videotrans\recognition\_whispernet.py", line 269, in _exec
System.MissingMethodException: 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)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "videotrans\task\only_one.py", line 47, in run
File "videotrans\task\_stage_recogn.py", line 62, in recogn
File "videotrans\recognition\__init__.py", line 205, in run
File "videotrans\recognition\_base.py", line 91, in run
File "videotrans\recognition\_whispernet.py", line 285, in _exec
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:/迅雷下载/修复/1-mp4,
临时文件夹: F:/pyvideotrans/tmp/20808/5c7d88d507
已选 清理已存在
未选 启用CUDA加速
已选 降噪
已选 识别说话人,最大说话人数量3
语音识别:Whisper.NET, model_name: ggml-large-v3.bin, 发音语言: 英语, 断句方式:默认断句
翻译渠道:兼容AI/本地模型,原始语言:英语,目标语言:简体中文, 已选 发送完整字幕
配音渠道:Qwen3-TTS(本地内置), 角色:clone, 配音语言:简体中文, 未选 二次语音识别
音量:+0%, 语速:+0%, 已选 音频加速, 未选 视频慢速
字幕: 嵌入硬字幕
已选 分离人声与背景声,存在分离后的纯净人声文件,存在分离后的背景声音文件
代理地址:


=
system:Windows-10-10.0.26100-SP0
version:v4.06
frozen:True
language:zh
root_dir:F:/pyvideotrans

9 Replies

这个错误的原因是 Whisper.net 所依赖的 .NET 运行时版本不匹配TimeSpan.FromMilliseconds(Int64) 方法需要 .NET 6 或更高版本,您当前的 .NET 运行时可能过旧(如 .NET Framework 4.x)或未正确安装。

解决方案:

  1. 安装 .NET 运行时:从微软官网下载并安装 .NET 6.0 或 .NET 8.0 运行时(桌面应用版)

  2. 安装后重启 pyVideoTrans,重新执行任务。

替代方案:

如果仍无法解决,请切换到 faster-whisper 语音识别渠道(默认内置,无需额外依赖),效果同样优秀且更稳定。在主界面语音识别下拉框中选择 faster-whisper(本地内置) 即可。

请查阅相关文档:

电脑上安装的就是.NET Desktop Runtime 6.0.36

仍然报错,说明程序加载的不是正确的 .NET 运行时。可能原因:

  1. 运行时位数错误:请确保安装的是 x64 版本的 .NET Desktop Runtime 6.0,而不是 x86(32位)。
  2. 需要更新到 .NET 8.0:Whisper.net 最新版本可能依赖 .NET 8.0。下载并安装 .NET 8.0 Desktop Runtime(x64):
    .NET 8.0 运行时下载
  3. 存在旧版本冲突:如果系统同时安装了 .NET Framework 4.x 和 .NET 6/8,可能导致加载顺序错误。尝试在控制面板中卸载所有 .NET 相关组件,然后重新安装纯净的 .NET 6.0 Desktop Runtime x64。

替代建议
切换回 faster-whisper(本地内置) 渠道,该渠道不依赖 .NET 运行时,且兼容性和性能均优于 Whisper.net。请在主界面语音识别下拉框中直接选择 faster-whisper(本地内置) 并选用 large-v3 模型,效果相同。


如果仍坚持使用 Whisper.net,请提供 dotnet --info 命令的输出以便进一步排查。

电脑上安装了64位的.NET Desktop Runtime 6.0和.NET Desktop Runtime 8.0两种

此错误是因为 Whisper.net 加载了错误的 .NET 运行时版本。尽管您安装了 .NET 6.0 和 8.0,但系统可能仍优先使用 .NET Framework 或不兼容的版本。

请按顺序尝试以下步骤:

  1. 强制使用 .NET 6.0 运行时
    打开命令提示符(管理员),执行:

    setx DOTNET_ROLL_FORWARD "LatestMajor"

    然后重启 pyVideoTrans。

  2. 重新安装 Whisper.net 依赖
    进入软件源码根目录(sp.py 所在文件夹),执行:

    uv sync --extra dotnet

    这会重新编译 Whisper.net 的 Python 绑定,确保与已安装的 .NET 运行时匹配。

  3. 如果仍无法解决,请直接切换至 faster-whisper(本地内置) 渠道——它不依赖 .NET 运行时,效果相同且更稳定。在主界面语音识别下拉框中选择 faster-whisper(本地内置),模型选 large-v3 即可。

PS C:\Users\Administrator> 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]

dotnet --info 输出看,环境完全正确:x64 的 .NET 6.0.36 和 8.0.29 均已安装并在 C:\Program Files\dotnet 下。问题在于 pythonnet(Python 侧的 .NET 桥接)可能没有加载到正确的运行时,或者 Whisper.net 的 .NET 代码被意外编译成依赖 .NET 8(而 pythonnet 回退到 .NET Framework)。请按顺序尝试以下操作:1. 设置环境变量,强制 pythonnet 使用 .NET 8 - 在运行 sp.exe 前,在命令提示符执行: cmd set DOTNET_ROLL_FORWARD=LatestMajor set DOTNET_ROLL_FORWARD_TO_PRERELEASE=1 - 然后从同一 cmd 窗口启动软件(cd 软件目录 && sp.exe)。2. 验证 pythonnet 版本 - 在软件源码目录下执行: uv run python -c "import clr; print(clr.__version__)" - 确保输出为 3.0.1 或更高。如果显示较低版本,请重新执行 uv sync --extra dotnet。3. 若仍失败,尝试完全使用 .NET 8 - 在控制面板中卸载所有 .NET 6.0 相关组件(保留 8.0),只保留 .NET 8.0。 - 然后重启软件。4. 最稳定方案:切换到 faster-whisper - Whisper.NET 本身依赖较多,建议改用 faster-whisper(本地内置) 渠道,模型选 large-v3。该渠道不依赖 .NET,效果相同且更稳定。如果以上方法均无法解决,请提供 uv run python -c "import clr; print(clr.__version__)"echo %DOTNET_ROLL_FORWARD% 的输出,以便进一步排查。

F:\pyvideotrans>uv run python -c "import clr; print(clr.__version__)"
warning: No requires-python value found in the workspace. Defaulting to >=3.12.
× No solution found when resolving dependencies for split (markers: python_full_version >= '3.13'):
╰─▶ Because some-dotnet-package was not found in the package registry and your-project-name[dotnet] depends on

  some-dotnet-package==1.0.0, we can conclude that your-project-name[dotnet]'s requirements are unsatisfiable.
  And because your project requires your-project-name[dotnet], we can conclude that your project's
  requirements are unsatisfiable.

  hint: While the active Python version is 3.12, the resolution failed for other Python versions supported by
  your project. Consider limiting your project's supported Python versions using `requires-python`.

F:\pyvideotrans>echo %DOTNET_ROLL_FORWARD%
%DOTNET_ROLL_FORWARD%

uv run 报错可以看出,当前环境中项目的 Python 版本要求与您实际运行的 Python 版本不匹配。项目需要 Python 3.10,但您系统默认的 Python 是 3.12,导致依赖解析失败,无法正常加载 Whisper.NET 所需的 pythonnet

请按以下步骤操作:

1. 使用 Python 3.10 环境

请确保您使用的 Python 版本为 3.10。推荐使用 conda 或 pyenv 创建独立的 3.10 环境,例如:

conda create -n pyvideotrans python=3.10
conda activate pyvideotrans

然后在该环境下重新执行安装:

uv sync --extra dotnet

2. 重新验证 Whisper.NET

安装成功后,运行测试命令:

uv run python -c "import clr; print(clr.__version__)"

应该输出 3.0.1 或更高版本。

3. 设置环境变量(可选但建议)

在启动软件前的命令行中执行:

set DOTNET_ROLL_FORWARD=LatestMajor

然后从同一命令行启动软件:

uv run sp.py

4. 如果仍无法解决,请直接换用 faster-whisper

Whisper.NET 依赖 .NET 桥接,容易因环境问题出错。faster-whisper 是内置首选渠道,无需额外安装 .NET 组件,效果一样。请在软件主界面的语音识别下拉框中选择 faster-whisper(本地内置),模型选 large-v3

请查阅相关文档:

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