Skip to content

Commit

Permalink
fix/legacy_play (#514)
Browse files Browse the repository at this point in the history
* fix/legacy_play

handle Playlist objects

use helper methods to parse the ocp stream from PluginStream objects

needs OpenVoiceOS/ovos-utils#257

* Update requirements.txt
  • Loading branch information
JarbasAl authored Jun 21, 2024
1 parent 1594bdc commit 1535a7e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
31 changes: 19 additions & 12 deletions ovos_core/intent_services/ocp_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from ovos_bus_client.util import wait_for_reply
from ovos_classifiers.skovos.classifier import SklearnOVOSClassifier
from ovos_classifiers.skovos.features import ClassifierProbaVectorizer, KeywordFeaturesVectorizer
from ovos_plugin_manager.ocp import load_stream_extractors, available_extractors
from ovos_plugin_manager.ocp import available_extractors
from ovos_utils import classproperty
from ovos_utils.gui import is_gui_connected, is_gui_running
from ovos_utils.log import LOG
Expand All @@ -26,11 +26,11 @@

try:
from ovos_utils.ocp import MediaType, PlaybackType, PlaybackMode, PlayerState, OCP_ID, \
MediaEntry, Playlist, MediaState, TrackState, dict2entry
MediaEntry, Playlist, MediaState, TrackState, dict2entry, PluginStream
from ovos_bus_client.apis.ocp import OCPInterface, OCPQuery
except ImportError:
from ovos_workshop.backwards_compat import MediaType, PlaybackType, PlaybackMode, PlayerState, OCP_ID, \
MediaEntry, Playlist, MediaState, TrackState, dict2entry
MediaEntry, Playlist, MediaState, TrackState, dict2entry, PluginStream
from ovos_bus_client.apis.ocp import OCPInterface as _OIF, OCPQuery as _OQ


Expand Down Expand Up @@ -982,15 +982,22 @@ def select_best(self, results: list, message: Message) -> MediaEntry:
# Legacy Audio subsystem API
def legacy_play(self, results: List[MediaEntry], phrase="",
message: Optional[Message] = None):
xtract = load_stream_extractors()
# for legacy audio service we need to do stream extraction here
# we also need to filter video results
results = [xtract.extract_stream(r.uri, video=False)["uri"]
for r in results
if r.playback == PlaybackType.AUDIO
or r.media_type in OCPQuery.cast2audio]

self.legacy_api.play(results, utterance=phrase)
res = []
for r in results:
if not (r.playback == PlaybackType.AUDIO or r.media_type in OCPQuery.cast2audio):
# we need to filter video results
continue
if isinstance(r, Playlist):
# get internal entries from the playlist
for e in r.entries:
res.append(e.uri)
elif isinstance(r, MediaEntry):
res.append(r.uri)
elif isinstance(r, PluginStream):
# for legacy audio service we need to do stream extraction here
res.append(r.extract_uri(video=False))

self.legacy_api.play(res, utterance=phrase)

player = self.get_player(message)
player.player_state = PlayerState.PLAYING
Expand Down
2 changes: 1 addition & 1 deletion requirements/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ ovos-plugin-manager<0.1.0, >=0.0.25
ovos-config~=0.0,>=0.0.13a8
ovos-lingua-franca>=0.4.7
ovos-backend-client~=0.1.0
ovos-workshop>=0.0.16a39
ovos-workshop>=0.0.16a40
# provides plugins and classic machine learning framework
ovos-classifiers<0.1.0, >=0.0.0a53

Expand Down

0 comments on commit 1535a7e

Please sign in to comment.