mirror of
https://github.com/markqvist/Sideband.git
synced 2024-10-01 03:15:37 -04:00
Platform audio handling
This commit is contained in:
parent
7cf53ba62a
commit
fb725ea4de
@ -56,7 +56,7 @@ class AndroidAudio(Audio):
|
||||
else:
|
||||
self._recorder.setAudioSource(AudioSource.DEFAULT)
|
||||
self._recorder.setAudioSamplingRate(48000)
|
||||
self._recorder.setAudioEncodingBitRate(32000)
|
||||
self._recorder.setAudioEncodingBitRate(16000)
|
||||
self._recorder.setAudioChannels(1)
|
||||
self._recorder.setOutputFormat(OutputFormat.OGG)
|
||||
self._recorder.setAudioEncoder(AudioEncoder.OPUS)
|
||||
|
@ -6,6 +6,8 @@ from pyobjus.dylib_manager import INCLUDE, load_framework
|
||||
from sbapp.plyer.facades import Audio
|
||||
from sbapp.plyer.platforms.macosx.storagepath import OSXStoragePath
|
||||
|
||||
import threading
|
||||
|
||||
load_framework(INCLUDE.Foundation)
|
||||
load_framework(INCLUDE.AVFoundation)
|
||||
|
||||
@ -28,6 +30,13 @@ class OSXAudio(Audio):
|
||||
|
||||
self._check_thread = None
|
||||
self._finished_callback = None
|
||||
self._loaded_path = None
|
||||
self.is_playing = False
|
||||
self.sound = None
|
||||
self.pa = None
|
||||
self.is_playing = False
|
||||
self.recorder = None
|
||||
self.should_record = False
|
||||
|
||||
def _check_playback(self):
|
||||
while self._player and self._player.isPlaying:
|
||||
@ -81,6 +90,18 @@ class OSXAudio(Audio):
|
||||
self._player = None
|
||||
|
||||
def _play(self):
|
||||
# Conversion of Python file path string to Objective-C NSString
|
||||
file_path_NSString = NSString.alloc()
|
||||
file_path_NSString = file_path_NSString.initWithUTF8String_(
|
||||
self._file_path
|
||||
)
|
||||
|
||||
# Definition of Objective-C NSURL object for the output record file
|
||||
# specified by NSString file path
|
||||
file_NSURL = NSURL.alloc()
|
||||
file_NSURL = file_NSURL.initWithString_(file_path_NSString)
|
||||
self._current_file = file_NSURL
|
||||
|
||||
# Audio player instance initialization with the file NSURL
|
||||
# of the last recorded audio file
|
||||
self._player = AVAudioPlayer.alloc()
|
||||
@ -96,6 +117,12 @@ class OSXAudio(Audio):
|
||||
self._check_thread = threading.Thread(target=self._check_playback, daemon=True)
|
||||
self._check_thread.start()
|
||||
|
||||
def reload(self):
|
||||
self._loaded_path = None
|
||||
|
||||
def playing(self):
|
||||
return self.is_playing
|
||||
|
||||
|
||||
def instance():
|
||||
return OSXAudio()
|
||||
|
@ -308,6 +308,15 @@ class WinAudio(Audio):
|
||||
self._recorder = None
|
||||
self._player = None
|
||||
self._current_file = None
|
||||
self._check_thread = None
|
||||
self._finished_callback = None
|
||||
self._loaded_path = None
|
||||
self.is_playing = False
|
||||
self.sound = None
|
||||
self.pa = None
|
||||
self.is_playing = False
|
||||
self.recorder = None
|
||||
self.should_record = False
|
||||
|
||||
def _start(self):
|
||||
'''
|
||||
@ -390,6 +399,12 @@ class WinAudio(Audio):
|
||||
self._player = WinPlayer(device=open_params.wDeviceID)
|
||||
self._player.play()
|
||||
|
||||
def reload(self):
|
||||
self._loaded_path = None
|
||||
|
||||
def playing(self):
|
||||
return self.is_playing
|
||||
|
||||
|
||||
def instance():
|
||||
'''
|
||||
|
Loading…
Reference in New Issue
Block a user