Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
tts-client
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
周亚武
tts-client
Commits
5bc2cf8b
Commit
5bc2cf8b
authored
Aug 23, 2024
by
周亚武
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改合并mp3文件规则
parent
33f37b63
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
51 deletions
+29
-51
pom.xml
pom.xml
+8
-0
src/main/java/com/mortals/xhx/tts/utils/AddMp3Util.java
src/main/java/com/mortals/xhx/tts/utils/AddMp3Util.java
+21
-51
No files found.
pom.xml
View file @
5bc2cf8b
...
...
@@ -141,6 +141,8 @@
<version>
1.0.1
</version>
</dependency>
<!-- 引入 SpringMVC 相关依赖,并实现对其的自动配置 -->
<dependency>
<groupId>
org.springframework.boot
</groupId>
...
...
@@ -227,6 +229,12 @@
<version>
3.0.9
</version>
</dependency>
<dependency>
<groupId>
com.mpatric
</groupId>
<artifactId>
mp3agic
</artifactId>
<version>
0.9.1
</version>
</dependency>
</dependencies>
...
...
src/main/java/com/mortals/xhx/tts/utils/AddMp3Util.java
View file @
5bc2cf8b
package
com.mortals.xhx.tts.utils
;
import
com.mpatric.mp3agic.InvalidDataException
;
import
com.mpatric.mp3agic.Mp3File
;
import
com.mpatric.mp3agic.MpegFrame
;
import
com.mpatric.mp3agic.UnsupportedTagException
;
import
org.apache.commons.io.FileUtils
;
import
javax.sound.sampled.*
;
...
...
@@ -14,66 +18,32 @@ import java.util.List;
public
class
AddMp3Util
{
public
static
String
mergeMp3s
(
List
<
String
>
input
Files
)
throws
IOException
,
UnsupportedAudioFileException
,
LineUnavailable
Exception
{
String
output
File
=
"/tmp/"
;
public
static
String
mergeMp3s
(
List
<
String
>
input
Paths
)
throws
IOException
,
InvalidDataException
,
UnsupportedTag
Exception
{
String
output
Path
=
"/tmp/"
;
if
(
System
.
getProperty
(
"os.name"
).
startsWith
(
"Windows"
)){
//windows电脑测试路径
output
File
=
"F:\\\\"
;
output
Path
=
"F:\\\\"
;
}
File
file
=
new
File
(
output
File
+
"new.mp3"
);
File
file
=
new
File
(
output
Path
+
"new.mp3"
);
if
(
file
.
exists
())
{
file
.
delete
();
}
AudioFormat
format
=
null
;
TargetDataLine
targetLine
=
null
;
SourceDataLine
sourceLine
=
null
;
// 获取混音所需的格式
for
(
String
inputFile
:
inputFiles
)
{
FileOutputStream
fos
=
new
FileOutputStream
(
outputPath
);
for
(
String
inputPath
:
inputPaths
)
{
ClassLoader
classLoader
=
AddMp3Util
.
class
.
getClassLoader
();
InputStream
inputStream
=
classLoader
.
getResourceAsStream
(
input
File
);
String
fileName
=
input
File
.
substring
(
inputFile
.
lastIndexOf
(
"/"
)+
1
);
File
nowFile
=
new
File
(
output
File
+
fileName
);
InputStream
inputStream
=
classLoader
.
getResourceAsStream
(
input
Path
);
String
fileName
=
input
Path
.
substring
(
inputPath
.
lastIndexOf
(
"/"
)+
1
);
File
nowFile
=
new
File
(
output
Path
+
fileName
);
//转换
FileUtils
.
copyInputStreamToFile
(
inputStream
,
file
);
inputStream
.
close
();
AudioInputStream
audioInputStream
=
AudioSystem
.
getAudioInputStream
(
nowFile
);
if
(
format
==
null
)
{
format
=
audioInputStream
.
getFormat
();
}
// 处理其他文件...
}
// 打开目标数据行用于输出
DataLine
.
Info
info
=
new
DataLine
.
Info
(
TargetDataLine
.
class
,
format
);
targetLine
=
(
TargetDataLine
)
AudioSystem
.
getLine
(
info
);
targetLine
.
open
(
format
);
targetLine
.
start
();
FileUtils
.
copyInputStreamToFile
(
inputStream
,
nowFile
);
// 打开源数据行用于输入
info
=
new
DataLine
.
Info
(
SourceDataLine
.
class
,
format
);
sourceLine
=
(
SourceDataLine
)
AudioSystem
.
getLine
(
info
);
sourceLine
.
open
(
format
);
sourceLine
.
start
();
// 将源数据行连接到目标数据行
AudioInputStream
inputStream
=
new
AudioInputStream
(
new
SequenceInputStream
(
new
FileInputStream
(
inputFiles
.
get
(
0
)),
new
FileInputStream
(
inputFiles
.
get
(
1
))),
format
,
AudioSystem
.
NOT_SPECIFIED
);
// 将inputStream的内容复制到targetLine
AudioSystem
.
write
(
inputStream
,
AudioFileFormat
.
Type
.
WAVE
,
new
File
(
outputFile
));
// 关闭线路和流
targetLine
.
stop
();
targetLine
.
close
();
sourceLine
.
stop
();
sourceLine
.
close
();
inputStream
.
close
();
Mp3File
mp3
=
new
Mp3File
(
nowFile
);
byte
[]
buffer
=
mp3
.
getCustomTag
();
fos
.
write
(
buffer
);
mp3
.
removeCustomTag
();
fos
.
close
();
}
return
output
File
;
return
output
Path
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment