Skip to content

Commit

Permalink
add silk_to_wav
Browse files Browse the repository at this point in the history
  • Loading branch information
lemisky committed Dec 3, 2022
1 parent 5706b55 commit 07230c5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions pilk/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import tempfile
import wave

from .SilkDecoder import SilkDecoder
from .SilkEncoder import SilkEncoder
from ._pilk import *
Expand Down Expand Up @@ -36,3 +39,14 @@ def get_duration(silk_path: str, frame_ms: int = 20) -> int:
i += 1
silk.seek(silk.tell() + size)
return i * frame_ms


def silk_to_wav(silk: str, wav: str, rate: int = 24000):
"""silk 文件转 wav"""
pcm_path = tempfile.mktemp(suffix='.pcm')
decode(silk, pcm_path, pcm_rate=rate)
with open(pcm_path, 'rb') as pcm:
with wave.open(wav, 'wb') as f:
# noinspection PyTypeChecker
f.setparams((1, 2, rate, 0, 'NONE', 'NONE'))
f.writeframes(pcm.read())
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# noinspection SpellCheckingInspection
setup(
name='pilk',
version='0.2.1',
version='0.2.2',
description='python silk voice library',
long_description=long_description,
long_description_content_type='text/markdown',
Expand Down

0 comments on commit 07230c5

Please sign in to comment.