本文整理汇总了Python中threadpool.ThreadPool.queue_task方法的典型用法代码示例。如果您正苦于以下问题:Python ThreadPool.queue_task方法的具体用法?Python ThreadPool.queue_task怎么用?Python ThreadPool.queue_task使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类threadpool.ThreadPool
的用法示例。
在下文中一共展示了ThreadPool.queue_task方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render_rap
# 需要导入模块: from threadpool import ThreadPool [as 别名]
# 或者: from threadpool.ThreadPool import queue_task [as 别名]
def render_rap(self, msg_id, words):
# Make the length of words fit the melody
notes = sum(1 for pitch, beats in self._melody if pitch != REST)
diff = notes - len(words)
if diff < 0:
words = words[:diff]
else:
words = words + ['la'] * diff
delay = 0
offsets = {}
word_index = 0
word_count = len(words)
word_delays = []
word_paths = []
pool = ThreadPool(min(word_count, self._thread_pool))
for pitch, beats in self._melody:
duration = beats * self._spb
if pitch != REST:
word = words[word_index]
word_delays.append(delay)
word_path = '/tmp/%s-%s.wav' % (msg_id, word_index)
word_paths.append(word_path)
ssml = '<s><prosody pitch="%sHz" range="x-low">%s</prosody></s>' \
% (pitch, word)
def task(word_id, ssml, word_path):
offsets[word_id] = self._swift.tts_file(ssml, word_path)
pool.queue_task(task, (word_index, ssml, word_path))
word_index += 1
delay += duration
if word_index == word_count:
# Break here, rather than inside the if statement above, so that
# that delay is updated and equals the duration of the rap.
break
pool.join_all()
if not word_index:
# Didn't render any words!
return
# Mix the rap and the backing track
mix_path = '/tmp/%s-mix.wav' % msg_id
sox_args = [self.sox_path, '-M'] + word_paths \
+ [self._backing_sample, mix_path, 'delay'] \
+ [str(delay + offsets[i]) for i, delay in enumerate(word_delays)] \
+ ['remix',
','.join(str(channel) for channel in range(1, word_count + 2)),
'norm']
print(' '.join(sox_args))
subprocess.check_call(sox_args)
return mix_path