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

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

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

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

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

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

6 c. L/ q, p) b% B: W" {3 ~- j, f
为了配合whisper语音识别,需要将mp3,wav,mp4等格式转换为其所需要的
- X+ v2 S$ \7 D/ zsampleRate为16000的格式。( h9 }; d$ c5 c$ o6 A3 j
本工具为命令行工具,根据命令提示輸入源文件和目标文件的目录。
& y+ E# Z. `& |2 p执行后,会在目标目录生成和源文件相同目录结构的wave文件,
& c% W$ H' y3 c- O4 h供语音识别之用。
$ ?0 @6 I3 B3 G2 k' D5 r7 T: k/ V, a7 K! ~& c0 O& {. t$ w
本工具需要配合ffmpeg64.exe,Processing.NDI.Lib.x64.dll," U  w; n* j$ k1 i2 ~
可以从以下软件中获得。
8 }" F' M  P$ D$ G% W$ qhttps://softaro.net/ffmpeggui/" N$ i3 r8 M' x4 M  [. V1 ]; @
$ I0 ~; y; G0 a% Q0 |; L4 x
工具代码如下,vs2022编译即可
8 v4 G8 D* I, u' t; e
  1. using System;
    / {9 `- O7 x' A. m  x0 Q4 q
  2. using System.Diagnostics;
    " ^5 i# I6 v5 ]4 C8 v
  3. using System.IO;0 s% w9 A4 {1 ?# o
  4. # w# N7 \( X! i  [1 v+ A
  5. class Program/ I+ G- R: |/ l% u7 D+ F
  6. {
    6 S- T& {7 G6 {: G+ K+ m! k
  7.     static void Main(string[] args)/ t& o7 l" l/ ~9 {
  8.     {+ m0 {3 E* `" D' Q5 D
  9.         Console.WriteLine("cvtWave");
    $ R" L$ {( b' _
  10.         Console.WriteLine("请输入源文件夹路径 (folder1):");
    & K/ y2 Q- ^# U& l4 G
  11.         string sourceFolder = Console.ReadLine();4 M" ^, D2 U0 h5 y, z) L$ u* ]
  12.         Console.WriteLine("请输入目标文件夹路径 (folder2):");' M3 _* ^% W; b
  13.         string destinationFolder = Console.ReadLine();) t2 v, u. P- v5 t; [; F. C& ~# W

  14. - E7 X$ P, H9 S8 c
  15.         ConvertFilesToWAV(sourceFolder, destinationFolder);. a- I8 w" d. p* A
  16. ( A* \) f  k" K: a7 t9 ~5 R
  17.         Console.WriteLine("转换完成.");# M* |# B. ^# ]  m
  18.     }
    % e. p5 q- {& m0 ]
  19. ; u7 C4 J& C( @5 N' Q; J; L
  20.     static void ConvertFilesToWAV(string sourceFolder, string destinationFolder)
    7 K7 |) `& @" K* }6 t! ~8 v
  21.     {( _% y/ Q! j) N. S, F$ K: J
  22.         foreach (var sourceFilePath in Directory.GetFiles(sourceFolder, "*.*", SearchOption.AllDirectories))* S4 `! {& ?0 z# ^# H
  23.         {
    2 @' r2 [/ K# q
  24.             string extension = Path.GetExtension(sourceFilePath).ToLower();
    " [8 `9 Z$ p) g3 d, S! Q5 M

  25. " G  z' x; f4 E7 l$ h
  26.             if (extension == ".mp4" || extension == ".avi" || extension == ".mp3")
    , c& M% C# R4 @# D% y2 X: ?5 {
  27.             {0 x( u) q' q7 ]$ V
  28.                 string relativePath = Path.GetRelativePath(sourceFolder, sourceFilePath);8 ~3 m2 }( I$ b4 S% A( a
  29.                 string destinationFilePath = Path.Combine(destinationFolder, relativePath);
    ! X8 g0 s$ B: U8 N( L
  30.                 destinationFilePath = Path.ChangeExtension(destinationFilePath, ".wav");& j/ L( Y$ J+ p) R! A* ^

  31. / _; w) \" @3 Q2 f
  32.                 Directory.CreateDirectory(Path.GetDirectoryName(destinationFilePath));
    5 C# h- `  J9 r/ }+ F
  33. / F- }4 O+ X/ g& k4 a& f! Z  G
  34.                 string ffmpegArgs = $"-i \"{sourceFilePath}\" -f wav -vn -b:a 256K -ar 16000 -y \"{destinationFilePath}\"";
    8 D+ Z6 i1 b+ g, \( |- g3 \

  35. " [& k) j9 m, E: Y
  36.                 Process ffmpegProcess = new Process
    5 d6 ]/ o5 o  o+ ~/ n6 |6 Y; \9 K5 y% R
  37.                 {6 D: L+ d- u0 U2 U# u% P, A
  38.                     StartInfo = new ProcessStartInfo
    8 x" Z4 L2 b3 Q2 V- i
  39.                     {: K$ j  l" S/ t3 U; ]1 h
  40.                         FileName = "ffmpeg64.exe",* c, }' B- e) a; i
  41.                         Arguments = ffmpegArgs,# v* p3 ]1 i1 P* X7 {" X$ s
  42.                         UseShellExecute = false,
    - U/ T1 I3 G3 p3 m5 X6 t3 `
  43.                         RedirectStandardError = true,
    % w2 E1 p/ b4 [1 Y
  44.                         CreateNoWindow = true
    % f: r9 h4 x1 k5 i5 S5 W. H. K
  45.                     }! H8 S" ~" E5 s% o+ L( n8 B. h
  46.                 };
    - Q7 u3 u$ y5 e

  47. 7 L8 Y; L, B7 }9 f$ h+ M5 k
  48.                 ffmpegProcess.Start();; t* T& U) \; S) M1 |

  49. 3 X; k: p1 v9 x, N4 b
  50.                 while (!ffmpegProcess.StandardError.EndOfStream)
    2 g, \! p  A- W% h" {
  51.                 {
    # N. e4 ^9 N7 O! [- B0 r) W% p
  52.                     string line = ffmpegProcess.StandardError.ReadLine();
    % H- h8 i$ }1 h. x; F
  53.                     Console.WriteLine(line);
    ( T) b3 J6 e' r: E/ e5 ?: X0 G
  54.                 }
    + {! C/ c5 _7 N5 B- I

  55. ; O3 t) s7 t. }: @% `# `
  56.                 ffmpegProcess.WaitForExit();
    / a9 K; \' H  g* a: \6 Z% p
  57.             }
    % g" _0 U2 R5 o) `" d8 h: ?
  58.         }0 F0 S  j( Z0 e
  59.     }
    2 e8 W* k- I. P4 Z; y
  60. }( U0 v. g, b8 y1 Q4 I2 y" s+ p
复制代码
! R7 [7 t& D  B' ]+ b2 c

8 v  g  H- X, Y+ Z3 k! C
0 A* v( n1 x# l& h) _: ]
- t5 a& m4 W* z! A8 n
分享到:  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日,是全球华人共同的冒险解谜类游戏家园。我们致力于提供各类冒险游戏资讯供大家学习交流。本站所有资源均不用于商业用途。

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