Speech parameters for picospeaker

merge-requests/21/head
Bob Mottram 2021-03-02 15:13:10 +00:00
parent cf175244cc
commit 5253e433de
2 changed files with 19 additions and 11 deletions

View File

@ -1946,24 +1946,26 @@ if args.speaker:
if speakerJson:
if speakerJson['say'] != prevSay:
if speakerJson.get('name'):
# Get the speech parameters, based upon the speaker's name
# echo spoken text to the screen
nameStr = speakerJson['name']
print(html.unescape(nameStr) + ': ' +
html.unescape(speakerJson['say']) + '\n')
pitch = getSpeakerPitch(nameStr)
if args.screenreader == 'espeak':
espeak.set_parameter(espeak.Parameter.Pitch, pitch)
rate = getSpeakerRate(nameStr)
if args.screenreader == 'espeak':
espeak.set_parameter(espeak.Parameter.Rate, rate)
# get the speech parameters
pitch = getSpeakerPitch(nameStr, args.screenreader)
rate = getSpeakerRate(nameStr, args.screenreader)
srange = getSpeakerRange(nameStr)
# say the speaker's name
if args.screenreader == 'espeak':
espeak.set_parameter(espeak.Parameter.Pitch, pitch)
espeak.set_parameter(espeak.Parameter.Rate, rate)
espeak.set_parameter(espeak.Parameter.Range, srange)
espeak.synth(html.unescape(nameStr))
elif args.screenreader == 'picospeaker':
os.system('picospeaker "' +
os.system('picospeaker ' +
'-r ' + str(rate) +
' -p ' + str(pitch) + ' "' +
html.unescape(nameStr) + '"')
time.sleep(3)
@ -1978,7 +1980,9 @@ if args.speaker:
if args.screenreader == 'espeak':
espeak.synth(html.unescape(sayStr))
elif args.screenreader == 'picospeaker':
os.system('picospeaker "' +
os.system('picospeaker ' +
'-r ' + str(rate) +
' -p ' + str(pitch) + ' "' +
html.unescape(sayStr) + '"')
prevSay = speakerJson['say']

View File

@ -13,17 +13,21 @@ from session import getJson
from utils import getFullDomain
def getSpeakerPitch(displayName: str) -> int:
def getSpeakerPitch(displayName: str, screenreader: str) -> int:
"""Returns the speech synthesis pitch for the given name
"""
random.seed(displayName)
if screenreader == 'picospeaker':
return random.randint(-79, 39)
return random.randint(1, 100)
def getSpeakerRate(displayName: str) -> int:
def getSpeakerRate(displayName: str, screenreader: str) -> int:
"""Returns the speech synthesis rate for the given name
"""
random.seed(displayName)
if screenreader == 'picospeaker':
return random.randint(-90, 9900)
return random.randint(50, 120)