mirror of
https://github.com/liberatedsystems/openCom-Companion.git
synced 2024-11-22 13:30:36 +01:00
Import variations
This commit is contained in:
parent
050b3aa17a
commit
551949b808
@ -11,7 +11,11 @@ if RNS.vendor.platformutils.is_android():
|
|||||||
import pyogg
|
import pyogg
|
||||||
from pydub import AudioSegment
|
from pydub import AudioSegment
|
||||||
else:
|
else:
|
||||||
import sbapp.pyogg as pyogg
|
if RNS.vendor.platformutils.is_linux():
|
||||||
|
from sbapp.pyogg import OpusFile, OpusBufferedEncoder, OggOpusWriter
|
||||||
|
else:
|
||||||
|
from pyogg import OpusFile, OpusBufferedEncoder, OggOpusWriter
|
||||||
|
|
||||||
from sbapp.pydub import AudioSegment
|
from sbapp.pydub import AudioSegment
|
||||||
|
|
||||||
codec2_modes = {
|
codec2_modes = {
|
||||||
@ -28,7 +32,7 @@ codec2_modes = {
|
|||||||
|
|
||||||
def samples_from_ogg(file_path=None):
|
def samples_from_ogg(file_path=None):
|
||||||
if file_path != None and os.path.isfile(file_path):
|
if file_path != None and os.path.isfile(file_path):
|
||||||
opus_file = pyogg.OpusFile(file_path)
|
opus_file = OpusFile(file_path)
|
||||||
audio = AudioSegment(
|
audio = AudioSegment(
|
||||||
bytes(opus_file.as_array()),
|
bytes(opus_file.as_array()),
|
||||||
frame_rate=opus_file.frequency,
|
frame_rate=opus_file.frequency,
|
||||||
@ -52,12 +56,12 @@ def samples_to_ogg(samples=None, file_path=None):
|
|||||||
|
|
||||||
channels = 1; samples_per_second = 8000; bytes_per_sample = 2
|
channels = 1; samples_per_second = 8000; bytes_per_sample = 2
|
||||||
|
|
||||||
opus_buffered_encoder = pyogg.OpusBufferedEncoder()
|
opus_buffered_encoder = OpusBufferedEncoder()
|
||||||
opus_buffered_encoder.set_application("audio")
|
opus_buffered_encoder.set_application("audio")
|
||||||
opus_buffered_encoder.set_sampling_frequency(samples_per_second)
|
opus_buffered_encoder.set_sampling_frequency(samples_per_second)
|
||||||
opus_buffered_encoder.set_channels(channels)
|
opus_buffered_encoder.set_channels(channels)
|
||||||
opus_buffered_encoder.set_frame_size(20) # milliseconds
|
opus_buffered_encoder.set_frame_size(20) # milliseconds
|
||||||
ogg_opus_writer = pyogg.OggOpusWriter(file_path, opus_buffered_encoder)
|
ogg_opus_writer = OggOpusWriter(file_path, opus_buffered_encoder)
|
||||||
|
|
||||||
frame_duration = 0.020
|
frame_duration = 0.020
|
||||||
frame_size = int(frame_duration * samples_per_second)
|
frame_size = int(frame_duration * samples_per_second)
|
||||||
|
Loading…
Reference in New Issue
Block a user