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

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

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

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

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

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


! `) u4 d5 d& W3 j2 h为了配合whisper语音识别,需要将mp3,wav,mp4等格式转换为其所需要的9 m- t8 p' U+ e  G. }" z  L
sampleRate为16000的格式。
5 h7 `  g+ ^+ l+ f* d本工具为命令行工具,根据命令提示輸入源文件和目标文件的目录。
' u7 T- G) y4 C* f, e执行后,会在目标目录生成和源文件相同目录结构的wave文件,/ O" V2 ]( }, r; c3 M5 U6 n
供语音识别之用。: C( W) t& E5 A% p: @4 _8 s- K: O
) q  E* ?9 Q" V. X& h  I! x8 H9 C
本工具需要配合ffmpeg64.exe,Processing.NDI.Lib.x64.dll,
' x. q5 _/ s6 V) T, k6 z: K- P4 R可以从以下软件中获得。
2 x$ h& A2 @  Y  f& i0 s3 d( w8 ohttps://softaro.net/ffmpeggui/# z! p. Q* n' ?# w2 K( Z

9 G" r" {& \( w1 [$ n工具代码如下,vs2022编译即可
) x. @) q% z9 V- `3 l1 j
  1. using System;
    # t6 k, i3 r! r7 b7 E$ |
  2. using System.Diagnostics;7 n5 V0 E" r8 R% n/ J4 Q
  3. using System.IO;+ j8 [- @3 C! E& K4 I% F' x

  4. % Y* c7 O  y% Q2 ]1 B# T2 a
  5. class Program
    6 c0 X& v) |1 O4 C
  6. {4 ^$ D( L# A  \, I# h% K  k
  7.     static void Main(string[] args)
    ( I0 i- J' s2 I; ^2 E( O
  8.     {0 J& |3 @  O7 x8 t' X: c
  9.         Console.WriteLine("cvtWave");
    8 R2 S8 X3 }# k8 B  V  G, M
  10.         Console.WriteLine("请输入源文件夹路径 (folder1):");
    & @" O; s! }% j
  11.         string sourceFolder = Console.ReadLine();% G) }" d* _6 i" m
  12.         Console.WriteLine("请输入目标文件夹路径 (folder2):");
    + N. ]" j% f2 b& v  u6 c2 b
  13.         string destinationFolder = Console.ReadLine();
    ! c1 f( ]7 }9 S( ~/ v
  14. : \4 m5 G* B8 J% L: M/ K5 V
  15.         ConvertFilesToWAV(sourceFolder, destinationFolder);
    & ^0 T$ r4 c7 f& R1 [' E" s
  16.   ?1 P; C% ^. B% d
  17.         Console.WriteLine("转换完成.");
    ' m: M3 H  t" @, R* [  B" a/ J8 a
  18.     }
    ; x. s, I: [! m5 r2 f4 x6 R

  19. ) v& u9 ^8 o% T8 ~  g1 Z! J
  20.     static void ConvertFilesToWAV(string sourceFolder, string destinationFolder)
    2 i4 j0 r! v7 L7 x- H$ `( F
  21.     {; b: `- n4 U6 R
  22.         foreach (var sourceFilePath in Directory.GetFiles(sourceFolder, "*.*", SearchOption.AllDirectories))
    9 x$ f1 A9 `- q4 I4 `0 S( v
  23.         {2 q* Y- N# B) |: @! f9 r
  24.             string extension = Path.GetExtension(sourceFilePath).ToLower();
    - ?% N! f. s& y# ?& z
  25. . B. @( t/ [! c2 b# j- L3 E8 x
  26.             if (extension == ".mp4" || extension == ".avi" || extension == ".mp3")# x, j( W. D  C; W; m. Z1 a
  27.             {
    $ Z7 s! u/ K1 w0 T9 Q
  28.                 string relativePath = Path.GetRelativePath(sourceFolder, sourceFilePath);7 p5 D' |4 ~; E" Y( R
  29.                 string destinationFilePath = Path.Combine(destinationFolder, relativePath);
    2 v: _( D4 B! \4 B: w* |, r
  30.                 destinationFilePath = Path.ChangeExtension(destinationFilePath, ".wav");
    ) J1 _& ~9 h6 M8 [+ v" p1 b
  31. 9 [0 L# ^4 t# a' o# o: o, j6 V* f
  32.                 Directory.CreateDirectory(Path.GetDirectoryName(destinationFilePath));
    5 m. x9 I, B/ z8 X: x
  33. ( J) f# q3 W, a, ~
  34.                 string ffmpegArgs = $"-i \"{sourceFilePath}\" -f wav -vn -b:a 256K -ar 16000 -y \"{destinationFilePath}\"";3 c: }& x8 `% D5 {/ C- Q% ^
  35. % K. i$ A  f1 a9 ~. g
  36.                 Process ffmpegProcess = new Process1 `* S6 H0 r# T3 _
  37.                 {
    5 m. Z0 w; X5 V: k& T! M2 {
  38.                     StartInfo = new ProcessStartInfo
    & |4 B! |( K# C# ?/ z* }; M
  39.                     {, V& O  q$ I2 _* K1 k" Q0 V, Z
  40.                         FileName = "ffmpeg64.exe",
    - F* a/ b" K: `, t, k6 }
  41.                         Arguments = ffmpegArgs,, m( [" e8 Z6 `
  42.                         UseShellExecute = false,
    2 [3 s: ?/ A; q/ x0 I/ \- _$ `$ _
  43.                         RedirectStandardError = true," `$ x  q1 j- B( w) H
  44.                         CreateNoWindow = true
    , v+ F1 P0 s3 m# T
  45.                     }6 ^6 s$ p. Z6 l4 e5 b
  46.                 };! H8 d0 G" {* E( _( m3 [: _

  47. : V/ [5 [3 o8 ^5 ^/ o* ]" G
  48.                 ffmpegProcess.Start();
    5 u8 E. k% s4 R

  49. 0 R6 }& g% o! {9 R+ R
  50.                 while (!ffmpegProcess.StandardError.EndOfStream). [" k- j7 w' [
  51.                 {
    : c' P4 l8 n' Q3 W% H& Y2 J
  52.                     string line = ffmpegProcess.StandardError.ReadLine();4 r& I; u* P0 @% ~2 t6 m
  53.                     Console.WriteLine(line);  L  V1 h1 t& V. ?$ l
  54.                 }- o+ x% @) C$ P! x0 z3 {( G# {( O

  55. % e  J: T  |$ s1 K  S
  56.                 ffmpegProcess.WaitForExit();1 O; h5 m( {% S
  57.             }
    - g5 ~" [2 f5 x3 v+ a, E& Z+ e* L! t
  58.         }
    ( h1 ~" a/ W* J
  59.     }
    4 c: g& r) ?8 y0 I. j' S
  60. }
    5 e7 b9 |7 N8 M% Y) y$ J- I1 r) r& m
复制代码
- H. R- F0 G2 {' @- f
/ h: u! t& g- |) S+ C
0 A, V% g: M0 L
+ }' r1 n) A& ]1 N
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 很美好很美好1 很差劲很差劲
回复

使用道具 举报

沙发
发表于 2025-4-4 01:05 | 只看该作者
学习学习一下
回复 支持 反对

使用道具 举报

高级模式
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日,是全球华人共同的冒险解谜类游戏家园。我们致力于提供各类冒险游戏资讯供大家学习交流。本站所有资源均不用于商业用途。

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