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

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

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

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

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

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

  W" C3 D0 l/ S* D3 m, u
为了配合whisper语音识别,需要将mp3,wav,mp4等格式转换为其所需要的1 M* c5 q+ p) U! h8 t. v  \  Q9 z
sampleRate为16000的格式。3 ^: v) l( x/ B1 m+ g
本工具为命令行工具,根据命令提示輸入源文件和目标文件的目录。
. o6 b8 O' j! d& |! b8 N执行后,会在目标目录生成和源文件相同目录结构的wave文件,: t9 |9 W& C1 U* x. I; [( ?( t% e
供语音识别之用。
1 |3 \- B" T# u% q8 ?5 }, R+ ~5 B+ P6 w3 K
本工具需要配合ffmpeg64.exe,Processing.NDI.Lib.x64.dll,. a/ u& m1 M3 r: _3 j% K7 E2 i
可以从以下软件中获得。
$ K* z! O' M( e3 Ihttps://softaro.net/ffmpeggui/
+ j: m3 h- O( N4 e; _
7 m. D- d9 [0 y* `5 W* h8 F6 a工具代码如下,vs2022编译即可
. j& ^) `$ d" v6 s
  1. using System;
    1 M: i" a9 R  P8 s) m6 y' A
  2. using System.Diagnostics;0 x8 u0 ~' x- b
  3. using System.IO;
    9 N3 [0 Y; |# K, G

  4. 7 M) P, }# h! z3 o
  5. class Program
    % y1 b5 P* Z4 A$ ?% u: Z$ m
  6. {3 D. F  l' b, C* V! F- N
  7.     static void Main(string[] args)4 Z2 J: v4 _0 N# E+ \  w1 o
  8.     {
    $ ]$ A0 Z  T7 |7 {6 X6 m
  9.         Console.WriteLine("cvtWave");/ N( d1 s8 P/ ]# X' l! G8 l4 s
  10.         Console.WriteLine("请输入源文件夹路径 (folder1):");. n$ d) o4 w% W6 q( F2 S& ~
  11.         string sourceFolder = Console.ReadLine();6 R- {+ B# f* D  l
  12.         Console.WriteLine("请输入目标文件夹路径 (folder2):");
    ' v  T4 C) i$ `& w# T! ]( I2 A
  13.         string destinationFolder = Console.ReadLine();1 e2 x' W6 n% k: B: n/ I
  14. , e- s; Z' }6 }
  15.         ConvertFilesToWAV(sourceFolder, destinationFolder);
    + s9 }- p$ l, {1 ?; F

  16. - U: B  b4 D1 z6 d% C  }6 U
  17.         Console.WriteLine("转换完成.");
    - E1 F& _' M- d0 i
  18.     }, H/ Z( D9 W, [3 n6 v' D
  19. 0 K% ?: n% }& s+ Q  }! `; F3 L
  20.     static void ConvertFilesToWAV(string sourceFolder, string destinationFolder)
    ; A- l  D4 k! D2 H9 a
  21.     {+ N/ r8 I, U% l7 h6 t$ p) H
  22.         foreach (var sourceFilePath in Directory.GetFiles(sourceFolder, "*.*", SearchOption.AllDirectories))
    & l" G& ~$ j* M7 K7 e& l+ Y
  23.         {
    , B; T$ J, O: s8 o" C* v- x" e
  24.             string extension = Path.GetExtension(sourceFilePath).ToLower();& B' [, t# s# D  P
  25. ) {# r  a/ v2 ]3 R2 ?7 q5 B$ c8 q
  26.             if (extension == ".mp4" || extension == ".avi" || extension == ".mp3")
    : i8 ?  K' f& X
  27.             {
    / t4 O+ ]+ @3 `5 D- C
  28.                 string relativePath = Path.GetRelativePath(sourceFolder, sourceFilePath);3 z4 M9 w* S# g3 S3 n
  29.                 string destinationFilePath = Path.Combine(destinationFolder, relativePath);
    / l5 L) Q( |7 U0 y' k( R
  30.                 destinationFilePath = Path.ChangeExtension(destinationFilePath, ".wav");. M7 p( u9 d6 q3 L
  31. 0 b" a9 j1 z0 ~9 g2 H9 j' y
  32.                 Directory.CreateDirectory(Path.GetDirectoryName(destinationFilePath));% k8 s! N. [; o, ^$ g* m
  33. 3 h5 o$ b) f  ?4 k6 ?/ E
  34.                 string ffmpegArgs = $"-i \"{sourceFilePath}\" -f wav -vn -b:a 256K -ar 16000 -y \"{destinationFilePath}\"";
    % W8 N% U# J' ]! [. ]/ y  `. H* ?! r

  35. . r, q0 a: y6 j( ~
  36.                 Process ffmpegProcess = new Process) M0 s$ e; X. z9 d% p
  37.                 {; ]' S+ w- i2 e+ [  ]7 @
  38.                     StartInfo = new ProcessStartInfo
    " K; {) A, o& Z
  39.                     {
    * v' D4 |7 R& W* B# z& Y  g
  40.                         FileName = "ffmpeg64.exe",7 K5 r8 U6 B4 d# I  x9 L
  41.                         Arguments = ffmpegArgs,! N) G  s0 E5 e
  42.                         UseShellExecute = false,
    8 A3 W( U3 e2 |
  43.                         RedirectStandardError = true,
    * v+ _2 C8 A0 f1 ?9 ]4 V% G' Z/ ?, F
  44.                         CreateNoWindow = true, g0 l* L' S3 {- w
  45.                     }
    , p  ~2 _4 ?% D5 Z/ ?
  46.                 };0 F' W7 N6 {; t, \* {- ^
  47. 3 X  R6 a3 S# u
  48.                 ffmpegProcess.Start();5 ~4 Z" Q" J$ F4 F$ V

  49. * l# a6 U9 R) Q$ }. V' e' A: p
  50.                 while (!ffmpegProcess.StandardError.EndOfStream)2 b5 B5 d7 }+ ^, H
  51.                 {# ^$ z: E5 ?( N3 G! y  L* c% Q
  52.                     string line = ffmpegProcess.StandardError.ReadLine();
    , t! [$ n4 c7 W" u0 l; T
  53.                     Console.WriteLine(line);* ^7 q& s: M- A3 z- J! p% z5 B; l5 U
  54.                 }
      x% ^5 l! ~2 a3 o  J3 Y
  55. ! `5 P* U& H/ h% l9 f: J
  56.                 ffmpegProcess.WaitForExit();  K# j& H' w1 h' \7 k. Z! o' I" r1 |
  57.             }
    " r  W& j" n6 g
  58.         }- w$ s# E1 |3 }. X% b
  59.     }
    & C4 }9 u1 e' @/ j! J9 e' _- z4 I
  60. }/ `1 y- w0 d7 _
复制代码

, c) H/ _" c! g9 J( x
8 e* g4 E, ^/ s7 M7 _4 L2 n: V: T2 n6 X& S# m

' M; B' c' K( Y
分享到:  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日,是全球华人共同的冒险解谜类游戏家园。我们致力于提供各类冒险游戏资讯供大家学习交流。本站所有资源均不用于商业用途。

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