冒险解谜游戏中文网 ChinaAVG
标题:
【汉化工具系列 #1】指定wave格式转换工具(cvtWave)
[打印本页]
作者:
shane007
时间:
2023-9-4 08:56
标题:
【汉化工具系列 #1】指定wave格式转换工具(cvtWave)
4 `) g$ q& c/ n% m
为了配合whisper语音识别,需要将mp3,wav,mp4等格式转换为其所需要的
( Y! ^% l/ ?/ _' l: K2 {
sampleRate为16000的格式。
, ?$ e7 Z" R' e
本工具为命令行工具,根据命令提示輸入源文件和目标文件的目录。
8 _& |; D# N& C
执行后,会在目标目录生成和源文件相同目录结构的wave文件,
d- f" h- I2 u6 @0 k
供语音识别之用。
! K- a1 Q% g C# k
8 d8 ~ {: V3 M% x N1 M' w) l3 W# A
本工具需要配合ffmpeg64.exe,Processing.NDI.Lib.x64.dll,
$ S. n& Y3 X" x4 A5 l2 `$ o% L
可以从以下软件中获得。
% E- y; @6 h# ]7 n/ ?
https://softaro.net/ffmpeggui/
% x S+ i1 u- \
0 a2 A2 W- i# j# o3 B9 m
工具代码如下,vs2022编译即可
$ R/ e' X' I8 N6 Z, m2 M) H* p4 R
using System;
9 q2 @' h1 P# R0 ^2 M
using System.Diagnostics;
9 \+ X @. S2 l
using System.IO;
3 z$ U$ R4 X( X" y6 f
6 B8 g$ U4 P1 `- C9 o* B! w& S
class Program
. T) J* [' _2 C
{
2 d' p& i# h* y
static void Main(string[] args)
" z/ |' D% M b3 z% }9 C0 v
{
. Y/ Z9 A5 z- C3 n
Console.WriteLine("cvtWave");
# d: Q% ?/ @/ z7 A0 z5 @
Console.WriteLine("请输入源文件夹路径 (folder1):");
- h, T# f' f& ]7 d/ W6 @; {
string sourceFolder = Console.ReadLine();
+ D6 q7 E$ [) g E! L7 X0 b1 R
Console.WriteLine("请输入目标文件夹路径 (folder2):");
8 Z g/ `" U; u8 o
string destinationFolder = Console.ReadLine();
* l/ F; s; O L3 g* [
* N; M: E6 }: h$ k, B" m- l
ConvertFilesToWAV(sourceFolder, destinationFolder);
/ U) O: ~7 B# Q: x( ^* E
3 {9 o4 _' c( z; d4 L* ?
Console.WriteLine("转换完成.");
9 R& o1 A h: j) {. ?5 Q8 v3 s
}
8 ^! W0 P6 I8 ?% f5 T5 u
: \5 ?( q( E( d' O. N
static void ConvertFilesToWAV(string sourceFolder, string destinationFolder)
% b* y3 r6 K2 L% ^8 B+ e
{
* e% o! ]. t0 P2 G
foreach (var sourceFilePath in Directory.GetFiles(sourceFolder, "*.*", SearchOption.AllDirectories))
7 `& E* E O( L0 B4 l" O
{
1 {& u1 t( Z. ~$ N9 z, ?/ w
string extension = Path.GetExtension(sourceFilePath).ToLower();
, A9 v# X$ s: D& J0 M' V) d
- t3 x' g/ g* t" I& t. W" E6 V% J
if (extension == ".mp4" || extension == ".avi" || extension == ".mp3")
* x B6 z1 _, W1 j+ p6 X |" h _
{
) B4 B$ e0 d* w7 @ @
string relativePath = Path.GetRelativePath(sourceFolder, sourceFilePath);
! s4 l |0 i/ @. M. J& T8 E
string destinationFilePath = Path.Combine(destinationFolder, relativePath);
0 n1 D. s, H4 `. c% p
destinationFilePath = Path.ChangeExtension(destinationFilePath, ".wav");
, W' P v( |0 X
& X8 J9 x; G& s9 N( g) u2 u1 h4 w
Directory.CreateDirectory(Path.GetDirectoryName(destinationFilePath));
- X4 G0 H( b" Y+ s- E3 X2 x9 m
0 p, v7 H; g h
string ffmpegArgs = $"-i \"{sourceFilePath}\" -f wav -vn -b:a 256K -ar 16000 -y \"{destinationFilePath}\"";
. y- Z9 e/ z2 N) h& M" O, u. Z) U
+ }' U1 [" m8 v/ G" g& a* y4 i* q
Process ffmpegProcess = new Process
0 H" a: q1 Z. z8 u+ X% b
{
; f% Z( `; g9 R8 Y2 ?
StartInfo = new ProcessStartInfo
1 x: P. l6 Z( X/ C) e
{
/ G/ M9 `" a& G% n$ U
FileName = "ffmpeg64.exe",
( q& n1 p8 S, B6 X# X+ ^* B% D
Arguments = ffmpegArgs,
, y. E8 l6 \0 M: ^6 G7 {1 f
UseShellExecute = false,
: r q5 {9 d5 k$ T
RedirectStandardError = true,
" K7 a2 [! v9 B; \- u
CreateNoWindow = true
7 ~" W& c6 A1 g g
}
% `( Z n7 Z0 X7 K1 }; `3 r! B' h- d
};
& d5 w/ A4 C; }, c/ E
" i% F4 T# S; M2 `5 k
ffmpegProcess.Start();
% j4 b7 E' c) h4 v
& w2 H$ i$ b. Q0 P! \; ^9 `+ {: i
while (!ffmpegProcess.StandardError.EndOfStream)
5 I- @# b# r2 g! m' P% b
{
9 w# M4 V! \2 U" W% _1 I3 U
string line = ffmpegProcess.StandardError.ReadLine();
5 V/ z, L$ ~* l6 g H( d! g5 Q! H
Console.WriteLine(line);
9 f& o6 f) I/ A% c' v
}
, C* z* `8 }% v7 d' B
$ G u, W7 M8 w. B3 s# B
ffmpegProcess.WaitForExit();
* w- g% H- ~1 R M2 m) h. _
}
7 ^2 R. X d+ A9 m6 o- ?: e
}
" N5 s( o3 R* i6 U$ Z6 H" C
}
$ |/ e5 O% n8 K0 { U7 _9 }% O
}
6 w+ @' H) B/ |! X
复制代码
- d% ]# X# r0 l
/ ^! i: `# n" E; O5 S( A
* `1 Y- z" \1 {9 W/ \+ F6 p
5 F5 a6 q& b" S3 x; ]" v
欢迎光临 冒险解谜游戏中文网 ChinaAVG (https://chinaavg.com/)
Powered by Discuz! X3.2