Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c60f051

Browse files
committed
refactor(audio_convert.py): remove redundant functions
1 parent 0f8dc91 commit c60f051

File tree

1 file changed

+2
-40
lines changed

1 file changed

+2
-40
lines changed

‎voice/audio_convert.py‎

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -62,52 +62,14 @@ def any_to_sil(any_path, sil_path):
6262
):
6363
shutil.copy2(any_path, sil_path)
6464
return 10000
65-
if any_path.endswith(".wav"):
66-
return pcm_to_sil(any_path, sil_path)
67-
if any_path.endswith(".mp3"):
68-
return mp3_to_sil(any_path, sil_path)
69-
raise NotImplementedError("Not support file type: {}".format(any_path))
70-
71-
72-
def mp3_to_wav(mp3_path, wav_path):
73-
"""
74-
把mp3格式转成pcm文件
75-
"""
76-
audio = AudioSegment.from_mp3(mp3_path)
77-
audio.export(wav_path, format="wav")
78-
79-
80-
def pcm_to_sil(pcm_path, silk_path):
81-
"""
82-
wav 文件转成 silk
83-
return 声音长度,毫秒
84-
"""
85-
audio = AudioSegment.from_wav(pcm_path)
86-
rate = find_closest_sil_supports(audio.frame_rate)
87-
# Convert to PCM_s16
88-
pcm_s16 = audio.set_sample_width(2)
89-
pcm_s16 = pcm_s16.set_frame_rate(rate)
90-
wav_data = pcm_s16.raw_data
91-
silk_data = pysilk.encode(wav_data, data_rate=rate, sample_rate=rate)
92-
with open(silk_path, "wb") as f:
93-
f.write(silk_data)
94-
return audio.duration_seconds * 1000
95-
96-
97-
def mp3_to_sil(mp3_path, silk_path):
98-
"""
99-
mp3 文件转成 silk
100-
return 声音长度,毫秒
101-
"""
102-
audio = AudioSegment.from_mp3(mp3_path)
65+
audio = AudioSegment.from_file(any_path)
10366
rate = find_closest_sil_supports(audio.frame_rate)
10467
# Convert to PCM_s16
10568
pcm_s16 = audio.set_sample_width(2)
10669
pcm_s16 = pcm_s16.set_frame_rate(rate)
10770
wav_data = pcm_s16.raw_data
10871
silk_data = pysilk.encode(wav_data, data_rate=rate, sample_rate=rate)
109-
# Save the silk file
110-
with open(silk_path, "wb") as f:
72+
with open(sil_path, "wb") as f:
11173
f.write(silk_data)
11274
return audio.duration_seconds * 1000
11375

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /