简体   繁体   English

在语音助手中拼写单词

[英]Spell A Word in Voice Assistant

I was working on a voice assistant in python with basic if elif statements.我正在使用基本的 if elif 语句在 python 中开发语音助手。 I am not able to solve on how to spell out a word by the assistant.我无法解决助手如何拼出单词的问题。 Did anyone work on this before and know how to solve it?以前有没有人研究过这个并且知道如何解决它?

You can use gTTS or pyttsx3 module.您可以使用 gTTS 或 pyttsx3 模块。 To see all, please visit this web.要查看所有内容,请访问网站。

pyttsx3 pyttsx3

# import the module
import pyttsx3

# initialise the pyttsx3 engine 
engine = pyttsx3.init() 

# convert text to speech 
engine.say("blah blah blah") 
engine.runAndWait()

gTTS gTTS

# Import the gTTS module
from gtts import gTTS

# This the os module so we can play the MP3 file generated
import os

# Generate the audio using the gTTS engine. We are passing the message and the 
language
audio = gTTS(text='I love Python for text to speech, and you?', lang='en')

# Save the audio in MP3 format
audio.save("message.mp3")

# Play the MP3 file
os.system("afplay message.mp3")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM