Add tempo factor for whole story and log messages with label

This commit is contained in:
Ruben van de Ven 2019-12-20 12:12:11 +01:00
parent a4292a3387
commit 7c7fcf071a
3 changed files with 36 additions and 9 deletions

View file

@ -128,7 +128,7 @@ class GoogleVoiceClient(object):
self.logger.log(LOG_BS,"wait for Google Voice")
if not self.isRunning.wait(timeout=1):
continue # re-ceck toBeShutdown
self.logger.debug("Starting Google Voice")
self.logger.debug(f"Starting Google Voice for {self.language_code}")
audio_generator = self.generator()

View file

@ -34,7 +34,7 @@ class Utterance(object):
self.lastUpdateTime = startTime
def setText(self, text, now):
self.text = text
self.text = text.lower() # always lowercase
self.lastUpdateTime = now
def hasText(self):
@ -173,6 +173,13 @@ class Message(object):
if self.label and len(self.label):
return self.label
return self.getText()
def getTextLabel(self):
"""
A combination of getText and getLabel for maximum verbosity
"""
l = f" ({self.label})" if self.label and len(self.label) else ""
return f"{self.getText()}{l}"
def setReply(self, reply):
self.reply = reply
@ -203,7 +210,7 @@ class Message(object):
return {
'id': self.id,
'time': None if self.reply is None else [u.startTime for u in self.reply.utterances],
'text': self.getText(),
'text': self.getTextLabel(),
'replyText': None if self.reply is None else [u.text for u in self.reply.utterances]
}
@ -212,7 +219,8 @@ class Message(object):
return self.audioFile
text = self.getText()
self.logger.debug(f"Fetching audio for {text}")
textlabel = self.getTextLabel()
self.logger.debug(f"Fetching audio for {textlabel}")
# return "test";
async with self.filenameFetchLock:
@ -236,7 +244,7 @@ class Message(object):
# print(threading.enumerate())
self.logger.debug(f"Fetched audio for {text}: {filename}")
self.logger.debug(f"Fetched audio for {textlabel}: {filename}")
return filename
@ -1174,6 +1182,7 @@ class Configuration(object):
volume = 1 # Volume multiplier for 'play' command
nothing_text = "nothing" # When variable is not set, but used in sentence, replace it with this word.
time_factor = 1
tempo_factor = 1
light0_intensity = 0
light0_fade = 30. # fade duration in seconds
light0_isSophie = False
@ -1884,7 +1893,7 @@ class Story(object):
# self.currentReply = self.currentMessage.reply
self.logger.info("Current message: ({0}) \"{1}\"".format(
message.id, message.getText()))
message.id, message.getTextLabel()))
if message.id != self.startMessage.id:
self.addToLog(message)
@ -1905,6 +1914,10 @@ class Story(object):
params = message.getParams().copy()
params['vol'] = params['vol'] * self.configuration.volume if 'vol' in params else self.configuration.volume
params['vol'] = "{:.4f}".format(params['vol'])
params['tempo'] = (float(params['tempo']) if 'tempo' in params else 1) * (float(self.configuration.tempo_factor) if hasattr(self.configuration, 'tempo_factor') else 1)
duration = float(duration) / params['tempo']
params['tempo'] = "{:.4f}".format(params['tempo'])
# self.hugvey.google.pause() # pause STT to avoid text events while decision is made
self.hugvey.sendCommand({

View file

@ -1096,7 +1096,7 @@ class Graph {
),
crel(
'label',
"Timing factor: (< 1 is faster, >1 is slower)",
"Condition timing factor: (< 1 is faster, >1 is slower)",
crel('input', {
'type': 'number',
'on': {
@ -1108,6 +1108,20 @@ class Graph {
'step': 0.01
})
),
crel(
'label',
"Playback tempo factor: (< 1 is faster, >1 is slower)",
crel('input', {
'type': 'number',
'on': {
'change': function(e){
panopticon.graph.configuration['tempo_factor'] = parseFloat(e.target.value)
}
},
'value': this.configuration.hasOwnProperty('tempo_factor') ? this.configuration.tempo_factor : 1,
'step': 0.01
})
),
crel('hr'),
crel('h2', 'Light fade setting #0'),
crel(
@ -1577,8 +1591,8 @@ class Graph {
),
crel( 'label',
crel( 'span', {
"title": "Playback pitch factor"
}, 'Pitch factor' ),
"title": "Playback pitch: negative: lower, positive: higher"
}, 'Pitch' ),
crel( 'input', {
'name': msg['@id'] + '-params.pitch',
'value': params.hasOwnProperty('pitch') ? params['pitch'] : 0,