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

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

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

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

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

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


. H; U+ e( v3 f* l  @; m为了配合whisper语音识别,需要将mp3,wav,mp4等格式转换为其所需要的1 e+ t6 M  a: p6 ?/ I
sampleRate为16000的格式。
8 C. G& m- c7 f  n) d本工具为命令行工具,根据命令提示輸入源文件和目标文件的目录。2 q" ]$ w6 k- _
执行后,会在目标目录生成和源文件相同目录结构的wave文件,
5 c5 }$ _$ \1 L$ Y- o& p供语音识别之用。$ V# }3 p8 m6 a: H+ n

8 z! t, O% ~# N3 }- T$ w% {& U本工具需要配合ffmpeg64.exe,Processing.NDI.Lib.x64.dll,
" ^/ J! N! q7 X3 G' k  R- C可以从以下软件中获得。' V/ `4 q2 V+ C% {8 w9 l
https://softaro.net/ffmpeggui/
! [" _3 I" x9 i* z/ k0 F( f
% Y- m! W/ N( R4 K$ M工具代码如下,vs2022编译即可6 M5 Q4 u$ U) Z( k0 K4 `
  1. using System;$ I% F4 E0 J2 w( {
  2. using System.Diagnostics;! \0 n+ y$ ]1 v: A
  3. using System.IO;
    7 Z+ U3 `- ?2 E3 o

  4. 0 U6 g4 H4 s$ I8 N" ?
  5. class Program, F7 @  b8 J. S: |+ v
  6. {! F9 m1 Y# e: c
  7.     static void Main(string[] args)
    & Y, _" k( ^6 @: q; S
  8.     {
    $ l5 T; m4 E3 p) v# S
  9.         Console.WriteLine("cvtWave");
    : c" r6 U' K! o* ?/ }, d
  10.         Console.WriteLine("请输入源文件夹路径 (folder1):");
      Q  {1 F! M7 F( E
  11.         string sourceFolder = Console.ReadLine();; d4 o0 v' P, ^
  12.         Console.WriteLine("请输入目标文件夹路径 (folder2):");
    6 Y, [4 u+ G! }# ^& w
  13.         string destinationFolder = Console.ReadLine();! G6 O) ?2 Q% B$ K% g6 g

  14. / P4 X% L1 q7 R0 l# a# t
  15.         ConvertFilesToWAV(sourceFolder, destinationFolder);& P1 U. ?$ O' D  W, }( x' F
  16. : w! }( E% v1 E+ o% y' p6 _! Q
  17.         Console.WriteLine("转换完成.");
    . L: N! y: A% k" g1 J$ P
  18.     }/ c5 w3 `' a8 s
  19. # z0 N6 q) S. H2 b/ Y" x: g  ~
  20.     static void ConvertFilesToWAV(string sourceFolder, string destinationFolder)7 {6 \. m9 c' B* D# |
  21.     {0 b; v! R# n9 I' \" \. S
  22.         foreach (var sourceFilePath in Directory.GetFiles(sourceFolder, "*.*", SearchOption.AllDirectories))
    3 K7 Y) H% B: S) E8 g. b% v  t
  23.         {
    8 z7 c, I7 J. p7 }7 E! S, z
  24.             string extension = Path.GetExtension(sourceFilePath).ToLower();% A+ Q/ @) ^6 [& Y  U( [

  25. 2 I( F8 T& X5 l+ ]
  26.             if (extension == ".mp4" || extension == ".avi" || extension == ".mp3")
    / M7 F% e/ [4 |7 u
  27.             {
    / d# ^) N( v; b+ ^0 H& d2 w
  28.                 string relativePath = Path.GetRelativePath(sourceFolder, sourceFilePath);& a! V5 z! d, ?  X( W) c
  29.                 string destinationFilePath = Path.Combine(destinationFolder, relativePath);
    " V8 m  q1 |7 j7 O3 r: W& o0 U3 T
  30.                 destinationFilePath = Path.ChangeExtension(destinationFilePath, ".wav");, d* t8 Q* f4 D1 d# E

  31. * |' m& Y  R; s2 l. u
  32.                 Directory.CreateDirectory(Path.GetDirectoryName(destinationFilePath));  U9 P  y' _4 F! h

  33. : _6 P8 T0 U1 Y' X6 A# @7 p: ?
  34.                 string ffmpegArgs = $"-i \"{sourceFilePath}\" -f wav -vn -b:a 256K -ar 16000 -y \"{destinationFilePath}\"";
    : h: ~( L6 r0 ?
  35.   ]; [8 C/ ^' h! X* G
  36.                 Process ffmpegProcess = new Process
    9 H9 R/ S! x3 d
  37.                 {  k$ O0 y/ T  B5 {
  38.                     StartInfo = new ProcessStartInfo
    . y  _9 J% _3 W
  39.                     {
    ( a: n8 P0 G! @4 h$ V! W
  40.                         FileName = "ffmpeg64.exe",0 G% r8 O: }6 `. R4 f
  41.                         Arguments = ffmpegArgs,
    * P* I# X! h7 s) w! {, `! O
  42.                         UseShellExecute = false,, `) k0 X; F/ K6 \' ~6 ^
  43.                         RedirectStandardError = true,# G8 W7 A! r1 b' A
  44.                         CreateNoWindow = true  G0 m% w) E# T. O5 [7 z
  45.                     }
    5 ^1 A  F. C0 R/ B: {& D
  46.                 };) t. K3 M5 L4 I2 ~+ t) W

  47. " I+ Z8 y, d0 h9 h2 I
  48.                 ffmpegProcess.Start();- c( H* e; m6 z. ?8 B7 @$ G4 a
  49. ! ]: v& S& M! x# o
  50.                 while (!ffmpegProcess.StandardError.EndOfStream)
    4 \& w4 |: H3 C* m( X, G' q6 m7 b2 K
  51.                 {' H6 F. L+ M. U4 E2 P, W: e! x$ m: Z) s
  52.                     string line = ffmpegProcess.StandardError.ReadLine();8 ]4 |! Z8 t( P
  53.                     Console.WriteLine(line);7 X8 m; b" Y+ }! `# B- h
  54.                 }
    " S; h' s6 e- d7 e

  55. 8 N7 l: M8 H$ h5 [' H: b$ W8 \! A
  56.                 ffmpegProcess.WaitForExit();
    0 C, ?7 z2 e! `2 i" R6 b
  57.             }9 t, X( u/ b( t2 e. y* \; p4 n) J
  58.         }; H$ M) h) _! @! |: x
  59.     }
    1 N! C4 o( i" w, Y( f$ D3 w
  60. }
    : k5 E/ y) u, u: ]0 n
复制代码

' z! ]! m% t4 j2 }0 g, Y# B% D3 ~
& g( i3 ~2 ?6 t4 [7 M
* u/ m1 h: f+ d5 S* o: q2 `) [$ G: b0 ~- h0 R# g$ s5 @. T8 O
分享到:  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日,是全球华人共同的冒险解谜类游戏家园。我们致力于提供各类冒险游戏资讯供大家学习交流。本站所有资源均不用于商业用途。

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