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

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

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

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

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

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


, y% r- A6 v( b为了配合whisper语音识别,需要将mp3,wav,mp4等格式转换为其所需要的
6 R6 q2 X! @( g( `4 c1 `sampleRate为16000的格式。
8 N9 X, N- }7 Y# D6 z' z9 [" y! K本工具为命令行工具,根据命令提示輸入源文件和目标文件的目录。
' {3 F' |) ?0 S9 E0 |: [3 K! u执行后,会在目标目录生成和源文件相同目录结构的wave文件,
) D  t3 B' w* c) k* A6 p供语音识别之用。8 R2 r6 R0 l5 |# n+ T0 L' R
) u( }# Y4 g# P, m8 {% M
本工具需要配合ffmpeg64.exe,Processing.NDI.Lib.x64.dll,5 O& Z1 g! ?# M2 d5 c
可以从以下软件中获得。! Q" h3 z. j6 H  Y6 z
https://softaro.net/ffmpeggui/
6 {% {/ Z/ n" d& ^: c; z3 S
' T& S( j3 ?3 H7 K  [4 E# ^工具代码如下,vs2022编译即可+ k+ q% d% U/ X% x9 Y9 K
  1. using System;9 N- b% y/ D" {- R5 e9 L4 N
  2. using System.Diagnostics;6 ]6 W9 S( F) E: J! R1 M6 s; d
  3. using System.IO;% r& L: c: ~+ Y5 \% E- ]# S

  4. # n: H' p% A  a1 C  G9 E6 t
  5. class Program
    3 }; `6 D' L% H4 p0 e0 w3 r. _  T' U! t
  6. {
    8 \& r" s6 i* W9 d( i# i
  7.     static void Main(string[] args)+ D% Q9 @: a9 C) T
  8.     {7 u7 l7 M4 m2 L' |
  9.         Console.WriteLine("cvtWave");
    - t! _2 L! ]. a4 \1 {1 H9 D' p! u
  10.         Console.WriteLine("请输入源文件夹路径 (folder1):");* z! n' l2 {, F, c- v+ O, ]& z' @
  11.         string sourceFolder = Console.ReadLine();
    7 O4 p: V* f0 z0 }$ O# {+ J) Z
  12.         Console.WriteLine("请输入目标文件夹路径 (folder2):");
    3 O% c' s2 d. Z8 b- ?! ]) A
  13.         string destinationFolder = Console.ReadLine();
    ; y7 @6 ]$ X, C7 r

  14. ! y% G6 C* C6 i6 g' Q) z
  15.         ConvertFilesToWAV(sourceFolder, destinationFolder);1 O6 d1 u: o( J! H' a$ q. [5 U/ l; L1 l, p
  16. & J7 @) D( U, [8 q( q6 f- a
  17.         Console.WriteLine("转换完成.");
    ) J9 M: k# {- J. K; J+ ~* l
  18.     }
    * l- \9 o4 Z" j/ x( x: n/ H% K
  19. 6 M( |* F1 I3 t
  20.     static void ConvertFilesToWAV(string sourceFolder, string destinationFolder)& Q# x3 d; L+ @7 b1 Q
  21.     {
    9 m( l: w. i& _* L! r
  22.         foreach (var sourceFilePath in Directory.GetFiles(sourceFolder, "*.*", SearchOption.AllDirectories))
    6 c( D9 Y7 F% V1 j! d; ~( V
  23.         {
    ! `) p* ~/ u$ U0 X2 W$ c$ [
  24.             string extension = Path.GetExtension(sourceFilePath).ToLower();
    1 |$ I0 w( ?4 p8 q
  25. 9 M" ]1 {6 Q% [& T
  26.             if (extension == ".mp4" || extension == ".avi" || extension == ".mp3"), x9 e# k/ h! n: Q- Z
  27.             {
    * K3 j$ k! Y4 h8 t
  28.                 string relativePath = Path.GetRelativePath(sourceFolder, sourceFilePath);
    8 ?2 f# Y7 \" D2 ~. ?8 e: i
  29.                 string destinationFilePath = Path.Combine(destinationFolder, relativePath);
    0 ?# v; R, y4 A" U% \  L- d
  30.                 destinationFilePath = Path.ChangeExtension(destinationFilePath, ".wav");
    * w; B- Q/ X4 d' `9 o

  31. ( r9 T; e( A: b( U
  32.                 Directory.CreateDirectory(Path.GetDirectoryName(destinationFilePath));
    : A' n4 O4 _( {
  33. ' P  G- a0 x5 ?' C7 }% q
  34.                 string ffmpegArgs = $"-i \"{sourceFilePath}\" -f wav -vn -b:a 256K -ar 16000 -y \"{destinationFilePath}\"";' `0 ^! M; Y& I2 R- i
  35. 6 H* L( Y; P$ a  _
  36.                 Process ffmpegProcess = new Process( [% b" `0 a$ [0 r
  37.                 {: z" M- M! ^' Q* a
  38.                     StartInfo = new ProcessStartInfo
    1 r! b' F4 `3 k, ]
  39.                     {
    7 R0 e! M4 W+ w) k
  40.                         FileName = "ffmpeg64.exe",# P2 V% a6 h( k! n: c% {
  41.                         Arguments = ffmpegArgs,
    / W0 F, f5 s  n( v& ^- x' L- P
  42.                         UseShellExecute = false,3 @/ W& r; N2 }. y0 ^/ `1 S  ]
  43.                         RedirectStandardError = true,
    $ ~7 A  [$ T# i) T$ _% x
  44.                         CreateNoWindow = true9 m" C1 _) F* V% R
  45.                     }
    , b* o6 ]+ T$ r& R' M
  46.                 };/ b& c/ n; X( y

  47. - n0 D: ~6 H7 ]% t6 i
  48.                 ffmpegProcess.Start();6 R$ I* l% b4 B

  49. . L2 }1 d$ `% R: q7 O
  50.                 while (!ffmpegProcess.StandardError.EndOfStream)" {1 i/ b5 M: Q& J$ w
  51.                 {
    1 `" e: L6 V3 x
  52.                     string line = ffmpegProcess.StandardError.ReadLine();$ v% _, h, [* ]8 D) p. t% U
  53.                     Console.WriteLine(line);
    8 K& i( t7 d/ F  _8 V6 U( z
  54.                 }/ n  w2 a, N$ m2 L1 d
  55. " F% E7 l6 s) v- _; }
  56.                 ffmpegProcess.WaitForExit();3 t  _4 G; e9 S" C, w
  57.             }# c# M1 p9 m+ f3 D: I% S% [
  58.         }
    $ A) d- w& u6 Y8 u" z  W9 X
  59.     }
    2 a2 b8 w8 u  j; Y3 O! c
  60. }# e/ x1 |2 Q0 t  `& {+ T: F
复制代码
9 T1 A4 y( H4 J  u, I
! y* B4 y, W9 m' w) C

- b  |8 J: _2 Z- j. x# x+ a+ F% Q" \/ |) p4 z7 x& |* _! b% s
分享到:  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日,是全球华人共同的冒险解谜类游戏家园。我们致力于提供各类冒险游戏资讯供大家学习交流。本站所有资源均不用于商业用途。

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