设为首页收藏本站官方微博

建议 【汉化工具系列 #1】指定wave格式转换工具(cvtWave)

[复制链接]
查看: 356|回复: 0
打印 上一主题 下一主题

[建议] 【汉化工具系列 #1】指定wave格式转换工具(cvtWave)

跳转到指定楼层
楼主
发表于 2023-9-4 08:56 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

【汉化工具系列 #1】指定wave格式转换工具(cvtWave)

; q4 x: u. Q9 @4 ]& p
为了配合whisper语音识别,需要将mp3,wav,mp4等格式转换为其所需要的$ n# k# O( A0 c1 s! _/ b
sampleRate为16000的格式。
1 {' ?% p! E/ y8 z- A本工具为命令行工具,根据命令提示輸入源文件和目标文件的目录。
: a* V) {3 C1 I8 D. m/ e执行后,会在目标目录生成和源文件相同目录结构的wave文件,. q* c* ?5 V, Y* V5 J5 `
供语音识别之用。; |. M0 {) J% f6 p0 j5 d% y0 H

# Y* j$ [0 ]3 \1 i本工具需要配合ffmpeg64.exe,Processing.NDI.Lib.x64.dll,* |, p4 ^  U! t" W/ ]' @
可以从以下软件中获得。
% W) H3 h6 v" Uhttps://softaro.net/ffmpeggui/4 v: i5 y+ I# Q0 m9 S" n
- s4 ?5 C3 l* V4 I) D/ T- U/ S- j( z
工具代码如下,vs2022编译即可6 J+ O4 D  t) K# ^, V
  1. using System;% W) ]1 i+ y0 l: B+ j" a
  2. using System.Diagnostics;' G" [  r$ k) t+ F
  3. using System.IO;
    $ D% T, ^! A9 U+ l+ y5 M

  4. ! w7 @: W  G" t4 I  f  m
  5. class Program
    0 \$ F: `4 N) t, r
  6. {
    % G# k! n- w- E: f; G! F5 E8 v
  7.     static void Main(string[] args)
    3 u1 W8 c3 Q  Y- s7 F  {. p  `
  8.     {) r9 O2 R3 Y( F/ c
  9.         Console.WriteLine("cvtWave");
    0 C7 S( O  g5 x, \" M/ G7 g
  10.         Console.WriteLine("请输入源文件夹路径 (folder1):");
    4 }, }6 P1 @0 {6 \5 s5 D( b" A
  11.         string sourceFolder = Console.ReadLine();
    " k) B% P" U* N$ O+ q
  12.         Console.WriteLine("请输入目标文件夹路径 (folder2):");  L2 h1 H- V) n
  13.         string destinationFolder = Console.ReadLine();0 `; {/ z# W( d
  14.   P6 t0 e# i8 a4 g: H" g% G
  15.         ConvertFilesToWAV(sourceFolder, destinationFolder);( {0 `. \0 ]1 W- t' G' O
  16. 2 N' W0 c6 a$ M' l
  17.         Console.WriteLine("转换完成.");# `0 i8 u! X' ?6 ~. ?9 M
  18.     }
    0 K1 c5 k# M" v  z& b) G, E- x
  19. & Q$ d& x7 R* ?5 L+ e4 o% `  @
  20.     static void ConvertFilesToWAV(string sourceFolder, string destinationFolder); C: ?, Z! R" S: o' l. ]+ @0 q+ S
  21.     {& {! f% D, g7 B
  22.         foreach (var sourceFilePath in Directory.GetFiles(sourceFolder, "*.*", SearchOption.AllDirectories))
    ' i& M$ y. b( x$ f: b- S
  23.         {
    ! G; ]+ i' X3 }+ J
  24.             string extension = Path.GetExtension(sourceFilePath).ToLower();
    # G0 c; |, K; p' ?- b# `, d: t
  25. 2 k. x5 A4 R6 k
  26.             if (extension == ".mp4" || extension == ".avi" || extension == ".mp3"): T( y, M& ^+ {7 y. |- ]% I
  27.             {- D) e; m$ u% o3 Y( ^& r
  28.                 string relativePath = Path.GetRelativePath(sourceFolder, sourceFilePath);
    * Z6 o9 b* w' M, E  G
  29.                 string destinationFilePath = Path.Combine(destinationFolder, relativePath);$ z5 Z8 u; {* W3 c0 v# ?9 T% w# `* p+ M
  30.                 destinationFilePath = Path.ChangeExtension(destinationFilePath, ".wav");! l% C* C$ b  Z0 Q7 [6 [

  31. ! R1 r7 }. ^% @$ _
  32.                 Directory.CreateDirectory(Path.GetDirectoryName(destinationFilePath));! u1 _5 L3 V( n  ^. f
  33. % N4 p# b' l" u
  34.                 string ffmpegArgs = $"-i \"{sourceFilePath}\" -f wav -vn -b:a 256K -ar 16000 -y \"{destinationFilePath}\"";! w+ C* [1 B, s9 ?+ n

  35. 9 f8 d# u5 _9 A- ]0 b; P
  36.                 Process ffmpegProcess = new Process' ]4 y* F- I5 A. V- u) y
  37.                 {
    7 f% \, n2 H  D
  38.                     StartInfo = new ProcessStartInfo
    : r( S8 P+ h. G4 L- }
  39.                     {: R/ p9 ^5 C' f! Y
  40.                         FileName = "ffmpeg64.exe",% f* x* u+ Z4 c  U! q% K. F
  41.                         Arguments = ffmpegArgs,
    0 I/ x+ N' Z7 v: I" p
  42.                         UseShellExecute = false,% r) e% \: M7 }( U& Z7 i
  43.                         RedirectStandardError = true,* }* t1 c: B" a9 W, `; Q) Z3 p" _3 w
  44.                         CreateNoWindow = true
    . I# b& Z# P8 z) T3 K: p
  45.                     }2 H+ `/ Y# |# W1 R9 J' e
  46.                 };5 S1 P, `4 W3 J% t. F2 F3 Z

  47. 1 P# s* E# D' E, m+ Z" s3 d. r9 }6 E
  48.                 ffmpegProcess.Start();
    . v6 Q4 m4 h: i3 G% [  t
  49. 0 q: ]" \3 w, |
  50.                 while (!ffmpegProcess.StandardError.EndOfStream)( c, }0 K6 j6 M1 G
  51.                 {6 m* q& u9 m& O# b: u' U2 e
  52.                     string line = ffmpegProcess.StandardError.ReadLine();
    " t: T( C/ K/ G5 E  Q' |: W! K6 ~7 u
  53.                     Console.WriteLine(line);  Q% ?/ x' `0 k" q" }/ w+ |
  54.                 }
    # Y- c# l5 X! L. P! U) P

  55. ) H" n$ _6 w/ m3 X$ ~4 B
  56.                 ffmpegProcess.WaitForExit();
    ' j# g2 i8 P/ h0 a' h* }5 R
  57.             }( s3 P9 X; h9 m% s1 b; ?* U" c3 ?1 N
  58.         }
    4 G4 ], W) Y& M, c2 d
  59.     }$ O) C, K9 u; L1 H" [
  60. }
    * u7 x% N0 s  M$ Z- p
复制代码

- b7 G( ^/ G3 x& Z) j: h
- r7 L2 W! l3 ?' r( }# F7 v* t: k8 j5 `; M

# a7 e% O- p. ], T
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 很美好很美好 很差劲很差劲
回复

使用道具 举报

高级模式
B Color Image Link Quote Code Smilies

本版积分规则

冒险解谜游戏中文网 ChinaAVG

官方微博官方微信号小黑屋 微信玩家群  

(C) ChinaAVG 2004 - 2019 All Right Reserved. Powered by Discuz! X3.2
辽ICP备11008827号 | 桂公网安备 45010702000051号

冒险,与你同在。 冒险解谜游戏中文网ChinaAVG诞生于2004年9月9日,是全球华人共同的冒险解谜类游戏家园。我们致力于提供各类冒险游戏资讯供大家学习交流。本站所有资源均不用于商业用途。

快速回复 返回顶部 返回列表