[audio] Added getSupportedStreams() and UnsupportedAudioStreamException #3764
[audio] Added getSupportedStreams() and UnsupportedAudioStreamException #3764
Conversation
CAUTION: This is a change breaking PR for bindings using an I will post (or push) an example implementation later. |
Could you please also adapt the voice bundle?
|
Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
@SJKA Done. I also added potential examples for |
Thanks! Now, as you already predicted above, Travis has got another wish:
|
@SJKA Done. I applied those changes to binding.sonos, io. javasound and io.webaudio to prevent good boy Travis to fail again. |
Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it by intention that the newly introduced method getSupportedStreams
is actually not used anywhere? I thought the idea of it was to allow the framework to check it upfront, instead of having exceptions being thrown at runtime...
* Thrown when a requested {@link AudioStream} is not supported by an {@link AudioSource} or {@link AudioSink} | ||
* implementation | ||
* | ||
* @author Christoph Weitkamp - Added UnsupportedAudioStreamException |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put "Initial contribution and API" here.
@@ -184,12 +186,17 @@ protected void say(String text) { | |||
} | |||
} | |||
if (null == voice) { | |||
throw new TTSException("Unable to find a suitable voice"); | |||
throw new TTSException("Unable to find a voice"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why did you change this? It seems unrelated to this PR and the message is not correct anymore as the system probably was able to find a voice, but not one of the right locale.
@@ -139,20 +141,24 @@ public void say(String text, String voiceId, String sinkId) { | |||
} else if (voiceId.contains(":")) { | |||
// it is a fully qualified unique id | |||
String[] segments = voiceId.split(":"); | |||
tts = ttsServices.get(segments[0]); | |||
voice = getVoice(tts.getAvailableVoices(), segments[1]); | |||
tts = getTTS(segments[0]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you change this? This potentially returns you the default tts instead of the one specified in segments[0]
, so it unnecessarily complicates things here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed it for readability and to prevent NPE (in case of segment[0]
contains a not suitable value). Have a look at https://github.com/eclipse/smarthome/pull/3764/files#diff-2bdbf6176fb6bd9b1af9a6cb230b6293R472. The getTTS(String)
method returns exaclty the same like before (ttsServices.get(id)
).
IOUtils.closeQuietly(audioStream); | ||
throw new UnsupportedAudioStreamException( | ||
"Sonos can only handle FixedLengthAudioStreams and URLAudioStreams.", audioStream.getClass()); | ||
// TODO: Instead of throwing an exception, we could ourselves try to wrap it into a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this todo still relevant? If I understand @maggu2810 right, it should now be rather the framework, which decides to do the conversion to a FixedLengthAudioStream, in case it sees that the sink does not support anything else.
@@ -71,6 +75,11 @@ public void process(AudioStream audioStream) throws UnsupportedAudioFormatExcept | |||
} | |||
|
|||
@Override | |||
public Set<Class<? extends AudioStream>> getSupportedStreams() { | |||
return Collections.emptySet(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why empty? It supports ALL streams!
@kaikreuzer thanks for review. No, of course not. My intention was to change it in a follow-up PR. I can do that in this PR if you preferr. |
Many thanks @cweitkamp! Ok, all fine for me to make use of this feature in an upcoming PR. |
We need to remember that once the next ESH stable is pushed out, quite some bindings in openhab2-addons will break and need to be adapted. |
The timing looks not very good. Such a breaking API will prevent any update of OH2 bindings relying on it for any user running OH 2.1 during around 5 months. We have to pray that no urgent patch is needed for all impacted bindings. |
We are talking about changes on unstable development branches, so there should be no need for praying or anything. |
@cweitkamp: may we ask you to provide a fix for all broken OH2 bindings ? |
@lolodomo Yes of course. I am working on it. |
Closes #3566
Signed-off-by: Christoph Weitkamp github@christophweitkamp.de