Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
eshiled-new
/
funasr_web
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit b9023a8e
authored
Aug 22, 2024
by
‘chizw’
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[+]配置更改
1 parent
f1f51f35
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
13 deletions
utils/ali/upload_file.py
utils/finetune.py
utils/sound_util.py
utils/ali/upload_file.py
View file @
b9023a8
...
...
@@ -4,14 +4,14 @@ import requests
def
download_audio
(
url
,
output_path
):
"""Download audio file from URL."""
"""Download audio
s
file from URL."""
response
=
requests
.
get
(
url
)
with
open
(
output_path
,
'wb'
)
as
f
:
f
.
write
(
response
.
content
)
def
cut_audio
(
input_path
,
output_base_path
,
start_times
,
durations
):
"""Cut audio into multiple clips using FFmpeg."""
"""Cut audio
s
into multiple clips using FFmpeg."""
if
not
os
.
path
.
exists
(
os
.
path
.
dirname
(
output_base_path
)):
os
.
makedirs
(
os
.
path
.
dirname
(
output_base_path
))
...
...
@@ -37,12 +37,12 @@ def main():
start_times
=
[
0
,
10
,
20
]
durations
=
[
10
,
10
,
10
]
# Download the audio file
# Download the audio
s
file
audio_file_name
=
os
.
path
.
basename
(
audio_url
)
audio_file_path
=
os
.
path
.
join
(
output_directory
,
audio_file_name
)
download_audio
(
audio_url
,
audio_file_path
)
# Cut the audio file into clips
# Cut the audio
s
file into clips
cut_audio
(
audio_file_path
,
output_directory
+
'clip_'
,
start_times
,
durations
)
...
...
utils/finetune.py
View file @
b9023a8
...
...
@@ -33,7 +33,7 @@ def upload_file(fileName, filePath):
def
download_audio
(
url
,
output_path
):
"""Download audio file from URL."""
"""Download audio
s
file from URL."""
response
=
requests
.
get
(
url
)
with
open
(
output_path
,
'wb'
)
as
f
:
f
.
write
(
response
.
content
)
...
...
utils/sound_util.py
View file @
b9023a8
...
...
@@ -64,7 +64,7 @@ def increase_volume(file_path, gain_db):
def
sound_volume
(
url
):
# file_path = download_from_url(url)
file_path
=
"../audio/test.mp3"
file_path
=
"../audio
s
/test.mp3"
print
(
file_path
)
print
(
os
.
path
.
dirname
(
file_path
))
res
=
increase_volume
(
file_path
,
20
)
...
...
@@ -80,25 +80,25 @@ sound_volume(
# # 音频按大小强制分隔
# filename = "陕西店2-2.28-9.42.MP3"
# audio = AudioSegment.from_file(filename, format="MP3")
# audio
s
= AudioSegment.from_file(filename, format="MP3")
# # 获取音频的总时长(秒)
# duration_seconds = audio.duration_seconds
# duration_seconds = audio
s
.duration_seconds
# # 打印时长
# print(f"音频时长(秒): {duration_seconds}")
# # 计算中间位置
# middle_time = int(len(audio)*(80*60+28)/(99*60+14))
# middle_time = int(len(audio
s
)*(80*60+28)/(99*60+14))
# # 创建第一个分割(从开始到中间)
# first_segment = audio[:middle_time]
# first_segment = audio
s
[:middle_time]
# first_segment.export("first_half.mp3", format="mp3")
# # 创建第二个分割(从中间到结束)
# second_segment = audio[middle_time:]
# second_segment = audio
s
[middle_time:]
# second_segment.export("second_half.mp3", format="mp3")
# 音频合并
# filename = "陕西店2-2.28-9.42.MP3"
# audio = AudioSegment.from_file(filename, format="MP3")
# audio
s
= AudioSegment.from_file(filename, format="MP3")
# filename1 = "陕西店2-2.28-9.42.MP3"
# audio1 = AudioSegment.from_file(filename1, format="MP3")
# second_segment = audio + audio1
# second_segment = audio
s
+ audio1
# second_segment.export("new.mp3", format="mp3")
Write
Preview
Markdown
is supported
Attach a file
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 post a comment