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

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

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

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

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

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


0 g% P1 n( s6 s. S为了配合whisper语音识别,需要将mp3,wav,mp4等格式转换为其所需要的1 P- B! A' x  i& ]
sampleRate为16000的格式。, y; G# C0 V# Y! C, ~2 X8 B7 M
本工具为命令行工具,根据命令提示輸入源文件和目标文件的目录。
# X) a0 `6 p7 K6 u  Z2 k执行后,会在目标目录生成和源文件相同目录结构的wave文件,+ |( s% D$ j+ x) j# {8 }
供语音识别之用。
9 i# F! c8 F6 U  K) B( r) d& G5 ^) h9 f/ U5 m5 {1 O  G
本工具需要配合ffmpeg64.exe,Processing.NDI.Lib.x64.dll,! ^% B7 D2 ^) _- s2 u
可以从以下软件中获得。
9 A+ m  b" H0 z( z' Ghttps://softaro.net/ffmpeggui/- ~* S4 W3 \- S/ ^5 h
: I& J- ^1 b1 d5 \( e0 E+ g' }
工具代码如下,vs2022编译即可3 g2 G. o% S; ?7 R8 f# L/ |. Y) Q
  1. using System;
    " p* k/ p9 |: i# w' S
  2. using System.Diagnostics;
    8 a. C. t. a# t% [
  3. using System.IO;
    , C! m' X3 K) S! x
  4. 8 b. S, e2 z! f( A8 N6 G
  5. class Program- E" p2 C, t) [. Y% c) U& p6 m
  6. {
    & i( C  [3 m# {5 T" l! `
  7.     static void Main(string[] args)
    ) d' R( h: e  `1 s& S
  8.     {
    ( x' b( f% [" M# Q5 a" D1 z' A" q
  9.         Console.WriteLine("cvtWave");
    3 a% `. j/ }7 `( W$ M
  10.         Console.WriteLine("请输入源文件夹路径 (folder1):");9 G3 Z4 K$ Y9 y) f, B9 E' L5 j2 h
  11.         string sourceFolder = Console.ReadLine();
    ! A& T8 n3 [" Q+ Y' b
  12.         Console.WriteLine("请输入目标文件夹路径 (folder2):");8 u- R. I8 @  _% l
  13.         string destinationFolder = Console.ReadLine();1 ?( {% ~) _, N6 p5 V' I* T

  14. 5 [! i$ e! O. Y$ b7 J& h
  15.         ConvertFilesToWAV(sourceFolder, destinationFolder);1 [3 s, u5 n/ `$ w

  16. 8 D4 k3 ^4 ]. i- t
  17.         Console.WriteLine("转换完成.");
    ' Q5 H  e! b/ o3 M; \
  18.     }
    3 |- ~' T* J% H3 E, P' h: F
  19. 5 j8 h1 l  G: `4 @5 l" v0 s
  20.     static void ConvertFilesToWAV(string sourceFolder, string destinationFolder)
    8 Z6 }% C- R& A7 `# u3 }
  21.     {" H) }! Q# F1 @) W
  22.         foreach (var sourceFilePath in Directory.GetFiles(sourceFolder, "*.*", SearchOption.AllDirectories))2 E' G# a* E/ q2 c3 e
  23.         {! w6 J- C  k8 N" Z+ ]/ b# j+ g
  24.             string extension = Path.GetExtension(sourceFilePath).ToLower();" G4 w' M5 u' c& Y9 q/ U+ ?) i

  25. . `* d# I$ |7 M
  26.             if (extension == ".mp4" || extension == ".avi" || extension == ".mp3")
    0 a+ ?1 B+ Q3 y+ u
  27.             {
    , w" h: l* O6 a
  28.                 string relativePath = Path.GetRelativePath(sourceFolder, sourceFilePath);/ e7 \$ U9 N1 G$ U- [
  29.                 string destinationFilePath = Path.Combine(destinationFolder, relativePath);  |9 G* Q) P: q. `/ j' `
  30.                 destinationFilePath = Path.ChangeExtension(destinationFilePath, ".wav");3 k- o+ E% m; [' M) W

  31. 7 Q( }/ k: Q% i3 ?0 ]9 M
  32.                 Directory.CreateDirectory(Path.GetDirectoryName(destinationFilePath));
    - ?. V) y% I" ^
  33. # O/ G. s- c: m7 c) h
  34.                 string ffmpegArgs = $"-i \"{sourceFilePath}\" -f wav -vn -b:a 256K -ar 16000 -y \"{destinationFilePath}\"";+ j+ z4 @# {' v. ^& O
  35. - }5 o2 B7 ?4 H- r7 n$ b/ {
  36.                 Process ffmpegProcess = new Process; D5 K$ S1 T/ ]' q  q
  37.                 {
    * ]* v" }9 \" U) \3 g* ~* o
  38.                     StartInfo = new ProcessStartInfo) o# h, o) X+ C
  39.                     {& f, L6 V7 ?$ K+ c( j
  40.                         FileName = "ffmpeg64.exe",: g% U! v5 o* Q) u) x/ `
  41.                         Arguments = ffmpegArgs,
    6 }  C7 V4 F" `" G( D
  42.                         UseShellExecute = false,
    / Q5 B' D8 i/ E2 i$ X$ y% z8 @* G
  43.                         RedirectStandardError = true,
    # p. T& l/ j  |7 o) H4 P" u/ w
  44.                         CreateNoWindow = true
    $ U$ O) g8 u9 }3 u5 x
  45.                     }
    / O6 y' A. H: w, M
  46.                 };( v' ?) o& D* K# ^8 V

  47. 2 U+ {) J+ ]. Z# _1 l6 d
  48.                 ffmpegProcess.Start();4 Y% ]$ N, F2 i  H0 l2 m6 ^
  49. % H3 {/ A7 W( I  u
  50.                 while (!ffmpegProcess.StandardError.EndOfStream)+ I. ]) ?# u6 e, l. b
  51.                 {
    # u. M  u" j) M: Y" U: o' B. I. s
  52.                     string line = ffmpegProcess.StandardError.ReadLine();
    , {" \# j+ T, _4 l$ l$ b
  53.                     Console.WriteLine(line);
    6 M* M( X1 [) Y. d) g6 S
  54.                 }! c% l! I8 T! n. o

  55. 3 e# R/ M4 `& w& ?
  56.                 ffmpegProcess.WaitForExit();
    1 D# G: l0 t7 a  M0 Q
  57.             }3 S5 U; U) k/ H) p* u- S* G9 d
  58.         }
    ) S* Y8 k, O/ ~: h1 B& d: X
  59.     }
    5 g( f) B: n/ o& b
  60. }
    % r* m; l/ G7 L. B! }5 K1 n8 _! d
复制代码

  u& F, L+ c- u; t
9 }* F. ~) t/ g& X
% B1 ?! |$ S" E9 V, p0 @" L$ u. R3 h! f
分享到:  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日,是全球华人共同的冒险解谜类游戏家园。我们致力于提供各类冒险游戏资讯供大家学习交流。本站所有资源均不用于商业用途。

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