Library Speake3 ให้ wrapper รอบ ๆ Espeak เพื่อเขียนโปรแกรมที่มีประสิทธิภาพโดยใช้ฟังก์ชันการพูดแบบข้อความเป็นคำพูดของเครื่องยนต์ ESPEAK TTS ใน Python
- Linux system
- Espeak
- python3.x
หากติดตั้ง PIP เพียงทำ
pip3 install speake3
สคริปต์ง่ายๆโดยใช้โมดูล Speake;
>>> import speake3
>>>
>>> engine = speake3.Speake() # Initialize the speake engine
>>> engine.set('voice', 'en')
>>> engine.set('speed', '107')
>>> engine.set('pitch', '99')
>>> engine.say("Hello world!") #String to be spoken
>>> engine.talkback()
คุณสามารถดูเวอร์ชันของการติดตั้ง Espeak;
>>> version = engine.get("version")
>>> print(version)
คุณสามารถดูเสียงที่ติดตั้งในระบบของคุณทั้งโดยทั่วไปและโดยเฉพาะ
>>> voices = engine.get("voices") # General
>>> for voice in voices:
>>> print(voice)
>>> voices_2 = engine.get("voices", "en") # Specific
>>> for voice in voices_2:
>>> print(voice)
คุณสามารถตั้งค่าคุณสมบัติโดยใช้วิธีการตั้งค่า;
>>> engine.set("voice", "en") # voice attribute can be any VoiceName value or
>>> #File value gotten from the voices dictionaries
แอตทริบิวต์ที่เป็นไปได้ที่สามารถตั้งค่าได้คือ: textfile, stdin, amplitude, wordgap, capitals, line-length, pitch, speed, voice, wavfile, stdout, version, voices, text-encoding, markup, quiet, punct, split, write-pm, nopause
คุณสมบัติที่ได้รับการตั้งค่ายังสามารถไม่ได้
>>> engine.unset("speed")
>>> engine.unset("pitch")
หากคุณโทรหลายครั้งก่อนที่จะเรียกใช้วิธี TalkBack พารามิเตอร์สตริงทั้งหมดในวิธีการพูดจะพูดหลังจากที่อีกวิธีหนึ่งเนื่องจากพวกเขาอยู่ในคิวภายใน
>>> engine.say("Hello World")
>>> engine.say("Foo bar")
>>> engine.say("Monty Python")
>>> engine.talkback()