12parser = argparse.ArgumentParser(description=
'speech synthesizer example')
13parser.add_argument(
'--remote', default=
'/speechSynthesizer_nws', type=str, help=
'remote port')
15args = parser.parse_args()
19if not yarp.Network.checkNetwork():
20 print(
'Please start a YARP name server first')
23options = yarp.Property()
24options.put(
'device',
'speechSynthesizer_nwc_yarp')
25options.put(
'local',
'/speechSynthesizerExample/client')
26options.put(
'remote', args.remote)
28device = yarp.PolyDriver(options)
30if not device.isValid():
31 print(
'Remote device not available')
34synthesizer = device.viewISpeechSynthesizer()
37 print(
'Unable to get ISpeechSynthesizer interface')
40language = yarp.SVector(1)
42if not synthesizer.getLanguage(language):
43 print(
"Failed to get current language")
46print(f
"Current language: {language[0]}")
48voice = yarp.SVector(1)
50if not synthesizer.getVoice(voice):
51 print(
"Failed to get current voice")
54print(f
"Current voice: {voice[0]}")
56speed = yarp.DVector(1)
58if not synthesizer.getSpeed(speed):
59 print(
"Failed to get current speed")
62print(f
"Current speed: {speed[0]}")
64pitch = yarp.DVector(1)
66if not synthesizer.getPitch(pitch):
67 print(
"Failed to get current pitch")
70print(f
"Current pitch: {pitch[0]}")
72if not synthesizer.setLanguage(
"english"):
73 print(
"Failed to set language to English")
76print(
"Language set to English")
78if not synthesizer.setSpeed(1.0):
79 print(
"Failed to set speed to 1.0")
82print(
"Speed set to 1.0")
84text =
"Hello, world! This is a test of the speech synthesizer."
87if not synthesizer.synthesize(text, sound):
88 print(
"Failed to synthesize speech")
93if not synthesizer.setSpeed(0.5):
94 print(
"Failed to set speed to 0.5")
97print(
"Speed set to 0.5")
99if not synthesizer.synthesize(text, sound):
100 print(
"Failed to synthesize speech after setting speed to 0.5")
105if not synthesizer.setSpeed(2.0):
106 print(
"Failed to set speed to 2.0")
109print(
"Speed set to 2.0")
111if not synthesizer.synthesize(text, sound):
112 print(
"Failed to synthesize speech after setting speed to 2.0")
117if not synthesizer.setLanguage(
"spanish"):
118 print(
"Failed to set language to Spanish")
121print(
"Language set to Spanish")
123if not synthesizer.synthesize(text, sound):
124 print(
"Failed to synthesize speech in Spanish")
129if not synthesizer.setVoice(
"lessac"):
130 print(
"Failed to set voice to lessac")
133print(
"Voice set to lessac")
135if not synthesizer.synthesize(
"Oh hello there!", sound):
136 print(
"Failed to synthesize speech with lessac voice")