Skip to content

Commit

Permalink
添加 SilkEncoder / SilkDecoder 类
Browse files Browse the repository at this point in the history
  • Loading branch information
lemisky committed May 18, 2022
1 parent 7d38898 commit 2258eb3
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 0 deletions.
26 changes: 26 additions & 0 deletions pilk/SilkDecoder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""silk 解码"""
from typing import Literal

from ._pilk import decode

PCM_RATE = Literal[
# pcm data rate 可选值
8000, 12000, 16000, 24000, 32000, 44100, 48000
]

# Uplink loss estimate, in percent (0-100); default: 0
PACKET_LOSS = int


class SilkDecoder:
"""..."""

def __init__(self, pcm_rate: PCM_RATE = 24000, packet_loss: PACKET_LOSS = 0):
self.pcm_rate = pcm_rate
self.packet_loss = packet_loss

def decode(self, silk: str, pcm: str) -> int:
return decode(
silk, pcm,
pcm_rate=self.pcm_rate, packet_loss=self.packet_loss
)
70 changes: 70 additions & 0 deletions pilk/SilkEncoder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
"""silk 编码器"""
from typing import Literal

from ._pilk import encode

PCM_RATE = Literal[
# pcm data rate 可选值
8000, 12000, 16000, 24000, 32000, 44100, 48000
]

MAX_RATE = Literal[
# 最大内部采样率
8000, 12000, 16000, 24000 # default: 24000
]

COMPLEXITY = Literal[
# Set complexity
0, # low
1, # medium
2, # high (default)
]

PACKET_SIZE = Literal[
# Packet interval in ms
20, 40, 60, 80, 100
]

# 8000 ~ 48000 HZ
SILK_RATE = int

# Uplink loss estimate, in percent (0-100); default: 0
PACKET_LOSS = int


class SilkEncoder:
"""..."""

def __init__(
self,
pcm_rate: PCM_RATE = 24000,
silk_rate: SILK_RATE = None,
max_rate: MAX_RATE = 24000,
complexity: COMPLEXITY = 2,
packet_size: PACKET_SIZE = 20,
packet_loss: PACKET_LOSS = 0,
use_in_band_fec: bool = False,
use_dtx: bool = False,
):
self.pcm_rate = pcm_rate
self.silk_rate = silk_rate
self.max_rate = max_rate
self.complexity = complexity
self.packet_size = packet_size
self.packet_loss = packet_loss
self.use_in_band_fec = use_in_band_fec
self.use_dtx = use_dtx

def encode(self, pcm: str, silk: str, tencent: bool = False) -> int:
return encode(
pcm, silk,
self.pcm_rate,
self.silk_rate,
tencent,
self.max_rate,
self.complexity,
self.packet_size,
self.packet_loss,
self.use_in_band_fec,
self.use_dtx,
)
3 changes: 3 additions & 0 deletions pilk/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from .SilkDecoder import SilkDecoder
from .SilkEncoder import SilkEncoder
from ._pilk import *

__title__ = 'pilk'
__description__ = 'python silk codec binding'
__url__ = 'https://github.com/foyoux/pilk'
__version__ = '0.0.2'
# noinspection SpellCheckingInspection
__author__ = 'foyou'
__author_email__ = '[email protected]'
__license__ = 'Apache 2.0'
Expand Down

0 comments on commit 2258eb3

Please sign in to comment.