Support SBC in speaker.app

This commit is contained in:
Josh Wu
2023-08-18 17:12:43 +08:00
parent f4add16aea
commit ec4dcc174e
2 changed files with 5 additions and 15 deletions
+5 -15
View File
@@ -228,10 +228,11 @@ class FfplayOutput(QueuedOutput):
subprocess: Optional[asyncio.subprocess.Process] subprocess: Optional[asyncio.subprocess.Process]
ffplay_task: Optional[asyncio.Task] ffplay_task: Optional[asyncio.Task]
def __init__(self) -> None: def __init__(self, codec: str) -> None:
super().__init__(AacAudioExtractor()) super().__init__(AudioExtractor.create(codec))
self.subprocess = None self.subprocess = None
self.ffplay_task = None self.ffplay_task = None
self.codec = codec
async def start(self): async def start(self):
if self.started: if self.started:
@@ -240,7 +241,7 @@ class FfplayOutput(QueuedOutput):
await super().start() await super().start()
self.subprocess = await asyncio.create_subprocess_shell( self.subprocess = await asyncio.create_subprocess_shell(
'ffplay -acodec aac pipe:0', f'ffplay -f {self.codec} pipe:0',
stdin=asyncio.subprocess.PIPE, stdin=asyncio.subprocess.PIPE,
stdout=asyncio.subprocess.PIPE, stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE,
@@ -419,7 +420,7 @@ class Speaker:
self.outputs = [] self.outputs = []
for output in outputs: for output in outputs:
if output == '@ffplay': if output == '@ffplay':
self.outputs.append(FfplayOutput()) self.outputs.append(FfplayOutput(codec))
continue continue
# Default to FileOutput # Default to FileOutput
@@ -708,17 +709,6 @@ def speaker(
): ):
"""Run the speaker.""" """Run the speaker."""
# ffplay only works with AAC for now
if codec != 'aac' and '@ffplay' in output:
print(
color(
f'{codec} not supported with @ffplay output, '
'@ffplay output will be skipped',
'yellow',
)
)
output = list(filter(lambda x: x != '@ffplay', output))
if '@ffplay' in output: if '@ffplay' in output:
# Check if ffplay is installed # Check if ffplay is installed
try: try:
BIN
View File
Binary file not shown.