Skip to content

Commit

Permalink
feat:stream extraction
Browse files Browse the repository at this point in the history
use the stream extractors before delegating to audio service
  • Loading branch information
JarbasAl committed Sep 12, 2024
1 parent 4ac71b1 commit ecadb86
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
13 changes: 13 additions & 0 deletions ovos_audio/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,17 @@ def restore_volume(msg=message):
else:
LOG.debug("No audio service to restore volume of")

def _extract(self, tracks: List[Union[str, Tuple[str,str]]]) -> List[str]:
"""convert uris into real streams that can be played, eg. handle youtube urls"""
xtracted = []
xtract = load_stream_extractors() # @lru_cache, its a lazy loaded singleton
for t in tracks:
if isinstance(t, str):
xtracted.append(xtract.extract_stream(t, video=False))
else: # (uri, mime)
xtracted.append(xtract.extract_stream(t[0], video=False))
return xtracted

def play(self, tracks, prefered_service, repeat=False):
"""
play starts playing the audio on the prefered service if it
Expand All @@ -405,6 +416,8 @@ def play(self, tracks, prefered_service, repeat=False):

LOG.debug(f"track uri type: {uri_type}")

tracks = self._extract(tracks) # ensure playable streams

# check if user requested a particular service
if prefered_service and uri_type in prefered_service.supported_uris():
selected_service = prefered_service
Expand Down
4 changes: 4 additions & 0 deletions requirements/extras.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# TTS Plugins
ovos-tts-plugin-server>=0.0.2, <1.0.0

# Media Playback plugins
ovos_audio_plugin_simple>=0.1.0, <1.0.0
ovos-audio-plugin-mpv>=0.0.1, <1.0.0
ovos_plugin_common_play>=0.0.7, <1.0.0

# OCP plugins
Expand Down

0 comments on commit ecadb86

Please sign in to comment.