Commit b9023a8e by ‘chizw’

[+]配置更改

1 parent f1f51f35
...@@ -4,14 +4,14 @@ import requests ...@@ -4,14 +4,14 @@ import requests
def download_audio(url, output_path): def download_audio(url, output_path):
"""Download audio file from URL.""" """Download audios file from URL."""
response = requests.get(url) response = requests.get(url)
with open(output_path, 'wb') as f: with open(output_path, 'wb') as f:
f.write(response.content) f.write(response.content)
def cut_audio(input_path, output_base_path, start_times, durations): def cut_audio(input_path, output_base_path, start_times, durations):
"""Cut audio into multiple clips using FFmpeg.""" """Cut audios into multiple clips using FFmpeg."""
if not os.path.exists(os.path.dirname(output_base_path)): if not os.path.exists(os.path.dirname(output_base_path)):
os.makedirs(os.path.dirname(output_base_path)) os.makedirs(os.path.dirname(output_base_path))
...@@ -37,12 +37,12 @@ def main(): ...@@ -37,12 +37,12 @@ def main():
start_times = [0, 10, 20] start_times = [0, 10, 20]
durations = [10, 10, 10] durations = [10, 10, 10]
# Download the audio file # Download the audios file
audio_file_name = os.path.basename(audio_url) audio_file_name = os.path.basename(audio_url)
audio_file_path = os.path.join(output_directory, audio_file_name) audio_file_path = os.path.join(output_directory, audio_file_name)
download_audio(audio_url, audio_file_path) download_audio(audio_url, audio_file_path)
# Cut the audio file into clips # Cut the audios file into clips
cut_audio(audio_file_path, output_directory + 'clip_', start_times, durations) cut_audio(audio_file_path, output_directory + 'clip_', start_times, durations)
......
...@@ -33,7 +33,7 @@ def upload_file(fileName, filePath): ...@@ -33,7 +33,7 @@ def upload_file(fileName, filePath):
def download_audio(url, output_path): def download_audio(url, output_path):
"""Download audio file from URL.""" """Download audios file from URL."""
response = requests.get(url) response = requests.get(url)
with open(output_path, 'wb') as f: with open(output_path, 'wb') as f:
f.write(response.content) f.write(response.content)
......
...@@ -64,7 +64,7 @@ def increase_volume(file_path, gain_db): ...@@ -64,7 +64,7 @@ def increase_volume(file_path, gain_db):
def sound_volume(url): def sound_volume(url):
# file_path = download_from_url(url) # file_path = download_from_url(url)
file_path = "../audio/test.mp3" file_path = "../audios/test.mp3"
print(file_path) print(file_path)
print(os.path.dirname(file_path)) print(os.path.dirname(file_path))
res = increase_volume(file_path, 20) res = increase_volume(file_path, 20)
...@@ -80,25 +80,25 @@ sound_volume( ...@@ -80,25 +80,25 @@ sound_volume(
# # 音频按大小强制分隔 # # 音频按大小强制分隔
# filename = "陕西店2-2.28-9.42.MP3" # filename = "陕西店2-2.28-9.42.MP3"
# audio = AudioSegment.from_file(filename, format="MP3") # audios = AudioSegment.from_file(filename, format="MP3")
# # 获取音频的总时长(秒) # # 获取音频的总时长(秒)
# duration_seconds = audio.duration_seconds # duration_seconds = audios.duration_seconds
# # 打印时长 # # 打印时长
# print(f"音频时长(秒): {duration_seconds}") # print(f"音频时长(秒): {duration_seconds}")
# # 计算中间位置 # # 计算中间位置
# middle_time = int(len(audio)*(80*60+28)/(99*60+14)) # middle_time = int(len(audios)*(80*60+28)/(99*60+14))
# # 创建第一个分割(从开始到中间) # # 创建第一个分割(从开始到中间)
# first_segment = audio[:middle_time] # first_segment = audios[:middle_time]
# first_segment.export("first_half.mp3", format="mp3") # first_segment.export("first_half.mp3", format="mp3")
# # 创建第二个分割(从中间到结束) # # 创建第二个分割(从中间到结束)
# second_segment = audio[middle_time:] # second_segment = audios[middle_time:]
# second_segment.export("second_half.mp3", format="mp3") # second_segment.export("second_half.mp3", format="mp3")
# 音频合并 # 音频合并
# filename = "陕西店2-2.28-9.42.MP3" # filename = "陕西店2-2.28-9.42.MP3"
# audio = AudioSegment.from_file(filename, format="MP3") # audios = AudioSegment.from_file(filename, format="MP3")
# filename1 = "陕西店2-2.28-9.42.MP3" # filename1 = "陕西店2-2.28-9.42.MP3"
# audio1 = AudioSegment.from_file(filename1, format="MP3") # audio1 = AudioSegment.from_file(filename1, format="MP3")
# second_segment = audio + audio1 # second_segment = audios + audio1
# second_segment.export("new.mp3", format="mp3") # second_segment.export("new.mp3", format="mp3")
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!