Compare commits

...

2 commits

2 changed files with 11 additions and 4 deletions

View file

@ -8,6 +8,8 @@ from ovtk_audiencekit.core import Clip, Stream
class AudioAlert(PluginBase): class AudioAlert(PluginBase):
def setup(self, output=None, timeout_min=1, sample_rate=None, buffer_length=4096, force_stereo=True): def setup(self, output=None, timeout_min=1, sample_rate=None, buffer_length=4096, force_stereo=True):
self._cleanup_task = asyncio.create_task(self._cleanup())
self.force_stereo = force_stereo self.force_stereo = force_stereo
self.timeout_min = timeout_min self.timeout_min = timeout_min
self.clips = {} self.clips = {}
@ -20,8 +22,7 @@ class AudioAlert(PluginBase):
sample_rate = next((rate for rate in [44100, 48000] if Stream.check_rate(self.output_index, 1, rate))) sample_rate = next((rate for rate in [44100, 48000] if Stream.check_rate(self.output_index, 1, rate)))
except StopIteration: except StopIteration:
self.logger.warn('Target audio device does not claim to support common sample rates! Attempting playback at native rate of audio') self.logger.warn('Target audio device does not claim to support common sample rates! Attempting playback at native rate of audio')
self.sample_rate = sample_rate
self._cleanup_task = asyncio.create_task(self._cleanup())
def run(self, path, speed=1, keep_pitch=False, immediate=True, poly=1, **kwargs): def run(self, path, speed=1, keep_pitch=False, immediate=True, poly=1, **kwargs):
poly = int(poly) poly = int(poly)
@ -29,7 +30,8 @@ class AudioAlert(PluginBase):
clip = self.clips.get(key, [None, None])[0] clip = self.clips.get(key, [None, None])[0]
if clip is None: if clip is None:
clip = Clip(path, speed=speed, keep_pitch=keep_pitch, force_stereo=self.force_stereo) clip = Clip(path, speed=speed, keep_pitch=keep_pitch,
samplerate=self.sample_rate, force_stereo=self.force_stereo)
self.clips[key] = [clip, maya.now()] self.clips[key] = [clip, maya.now()]
else: else:
self.clips[key][1] = maya.now() self.clips[key][1] = maya.now()

View file

@ -19,6 +19,11 @@ class TextToSpeechPlugin(PluginBase):
self.speaker_wav = speaker_wav self.speaker_wav = speaker_wav
self.output_index = Stream.find_output_index(output) self.output_index = Stream.find_output_index(output)
try:
sample_rate = next((rate for rate in [44100, 48000] if Stream.check_rate(self.output_index, 1, rate)))
except StopIteration:
self.logger.warn('Target audio device does not claim to support common sample rates! Attempting playback at native rate of audio')
self.sample_rate = sample_rate
conf_overrides = {k[2:]: v for k, v in kwargs.items() if k.startswith('o_')} conf_overrides = {k[2:]: v for k, v in kwargs.items() if k.startswith('o_')}
@ -72,7 +77,7 @@ class TextToSpeechPlugin(PluginBase):
text += '.' text += '.'
filename = self.make_tts_wav(text) filename = self.make_tts_wav(text)
# TODO: Play direct from memory # TODO: Play direct from memory
clip = Clip(filename, force_stereo=True) clip = Clip(filename, force_stereo=True, samplerate=self.sample_rate)
stream = Stream(clip, self.output_index) stream = Stream(clip, self.output_index)
if wait: if wait:
async def play(): async def play():