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

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

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

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

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

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


0 e6 [* g' p- h% y, X  ?为了配合whisper语音识别,需要将mp3,wav,mp4等格式转换为其所需要的3 Z! R$ ?. I  W, P
sampleRate为16000的格式。8 ^" d7 n0 t0 t$ Z, {! m% L
本工具为命令行工具,根据命令提示輸入源文件和目标文件的目录。. Q" F% A# r/ J, k* z  a8 j- p5 q
执行后,会在目标目录生成和源文件相同目录结构的wave文件,6 Y( }* K3 m- N' [. \
供语音识别之用。  ~; q; [% {" ~# T% k6 C1 U
/ d# q9 c( A7 D. v# t1 f
本工具需要配合ffmpeg64.exe,Processing.NDI.Lib.x64.dll,
. e/ k4 K0 Y' Y) S  S5 w: p& y# h+ `可以从以下软件中获得。
. H3 v: r7 u( Ghttps://softaro.net/ffmpeggui/
: N( r7 F: P! o
* u+ v0 {- o5 |! l, F4 V工具代码如下,vs2022编译即可
( i; u: X& ], |; t  M+ X6 q+ m
  1. using System;
    ' \, x  y4 \  x- X* e
  2. using System.Diagnostics;7 F) ^) U3 H7 K$ X" L
  3. using System.IO;
    - n4 o$ @6 P8 s0 f, B

  4. 3 R& A# }: N9 e: B' }, Z* }& Y, z/ x
  5. class Program3 Y4 K! u' a3 N: ^
  6. {+ d  c4 S7 D4 w: x% ?$ z9 o: d
  7.     static void Main(string[] args)
    - M1 _) V2 E7 }1 i0 f/ `
  8.     {2 @* e! H0 l6 a* Y  R6 M/ j4 h0 V
  9.         Console.WriteLine("cvtWave");4 e$ ~7 g/ h. }1 u& W1 Y" k* Y; q
  10.         Console.WriteLine("请输入源文件夹路径 (folder1):");
      W: W( E$ P7 L& w& Z
  11.         string sourceFolder = Console.ReadLine();0 |/ U, x+ V* l7 y% J4 K
  12.         Console.WriteLine("请输入目标文件夹路径 (folder2):");
    1 s  l0 L$ `. p7 X
  13.         string destinationFolder = Console.ReadLine();
    ; d, ~+ Z% q& H, g
  14. * j# `( j% ^" r
  15.         ConvertFilesToWAV(sourceFolder, destinationFolder);
    % }6 U  V9 [+ `7 ?8 C6 X

  16. 2 Y$ {8 R3 p/ `- H1 i
  17.         Console.WriteLine("转换完成.");
    & b0 A' y1 |$ e7 E
  18.     }
    " Q7 s- K6 d6 X, d" L

  19. / s3 U: t* H# j: T
  20.     static void ConvertFilesToWAV(string sourceFolder, string destinationFolder)
    ( i2 }, K' j9 H% W0 E# s1 j+ f
  21.     {! u2 Q$ q% v* z$ z( }0 ^! c: \& N
  22.         foreach (var sourceFilePath in Directory.GetFiles(sourceFolder, "*.*", SearchOption.AllDirectories))
    8 _3 u9 b9 W' r8 [0 l
  23.         {( p  b3 t* `. H2 t4 l  _6 [
  24.             string extension = Path.GetExtension(sourceFilePath).ToLower();9 P# S& z: L" m, k) X; w7 v

  25.   t% v. j+ S. [* R# W# e
  26.             if (extension == ".mp4" || extension == ".avi" || extension == ".mp3")
    0 R( B1 M: t/ }+ ^1 Y
  27.             {1 g) E/ t  y, F9 @. y8 s& ]& n: T$ U# B
  28.                 string relativePath = Path.GetRelativePath(sourceFolder, sourceFilePath);
      L/ h" Y+ f4 Q+ K9 ~: n
  29.                 string destinationFilePath = Path.Combine(destinationFolder, relativePath);
    , y' t% o7 J0 @& l% o0 P9 k) y
  30.                 destinationFilePath = Path.ChangeExtension(destinationFilePath, ".wav");# r! L# J2 t* i+ @, m
  31. # o& N9 ~1 \  i6 i, b9 h% U. q
  32.                 Directory.CreateDirectory(Path.GetDirectoryName(destinationFilePath));
    7 Q+ B3 S$ a. B8 O. S+ D' x

  33. . k, j4 I, a! u2 d
  34.                 string ffmpegArgs = $"-i \"{sourceFilePath}\" -f wav -vn -b:a 256K -ar 16000 -y \"{destinationFilePath}\"";+ C( A+ x( c& h0 d
  35. # x2 ?0 N; ~% T$ d/ Y& R
  36.                 Process ffmpegProcess = new Process4 A' Y, @% p$ {
  37.                 {
    ) ?0 \; D- J* \! A
  38.                     StartInfo = new ProcessStartInfo
    ' q1 D0 ~; U: X. x
  39.                     {6 G" B7 G! n7 E- o# D
  40.                         FileName = "ffmpeg64.exe",
    4 o! h+ v# W- _/ R+ n7 i! J5 }
  41.                         Arguments = ffmpegArgs,
    0 U6 p% e( s% J9 ^: y* R) f
  42.                         UseShellExecute = false,
    0 n5 U. z! Q8 O7 e- e2 _+ ~/ ~
  43.                         RedirectStandardError = true,
    2 C% f3 s8 z+ _5 B
  44.                         CreateNoWindow = true; |. p2 W. L# C
  45.                     }
    $ l6 {1 l& G& @1 H4 s, R0 M
  46.                 };8 d! j( E. Z9 u7 Q2 s

  47. 4 |8 ^* p( L. j* P$ W+ {$ M: g
  48.                 ffmpegProcess.Start();
    " i8 @8 d$ D1 ]" v3 t, _; c

  49. ; g; U; i5 k- t8 M8 }$ F
  50.                 while (!ffmpegProcess.StandardError.EndOfStream)
      N, }1 N  y2 a  }/ |# f9 M
  51.                 {4 Y/ G6 \5 m  b0 x8 h+ X: ^9 h
  52.                     string line = ffmpegProcess.StandardError.ReadLine();
    - \& J" i) `2 p
  53.                     Console.WriteLine(line);: [- L7 f+ X" ~2 F' Q- f
  54.                 }6 F/ V! i: z  C1 b; q+ X# I$ [5 S4 h3 V

  55. 3 U, ~  I( Z( W7 U7 M
  56.                 ffmpegProcess.WaitForExit();7 R8 B/ \+ t% T
  57.             }
    / h9 [! N7 [$ G$ \
  58.         }1 B' Y- C) e0 b- w
  59.     }! m: F' m: O6 r) B/ M- W* G
  60. }
    $ B( }: `- R4 w. H) d- i* f7 _% T
复制代码

0 L( V2 x3 H- h1 E# S
) V/ c, R: p7 [7 \; y, g/ O# S* p- G# T* p
, f( a3 |& \) a! |
分享到:  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日,是全球华人共同的冒险解谜类游戏家园。我们致力于提供各类冒险游戏资讯供大家学习交流。本站所有资源均不用于商业用途。

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