Python语音转文字

import pyttsx3
import io
import sys
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
 
engine = pyttsx3.init()
engine.setProperty('voice', 'zh')
engine.say('请输入您要播放的文件路径')
engine.runAndWait()

path_dir = input('请输入您要播放的文件路径后回车:')


with open(path_dir, 'r') as f:
    engine = pyttsx3.init()
    engine.setProperty('voice', 'zh')
    lines = f.readlines()
    print('要说的话:',lines)
    for line in lines:
        engine.say(line)
    engine.runAndWait()


"""Saving Voice to a file"""
engine = pyttsx3.init()
engine.setProperty('voice', 'zh')
# On linux make sure that 'espeak' and 'ffmpeg' are installed
engine.save_to_file('迪迦奥特曼(dijia.top)', 'test.mp3')
engine.runAndWait()

engine.stop()

你可能感兴趣的:(语音识别,python)