-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
|