zoukankan      html  css  js  c++  java
  • pyttsx3--文字转语音库

    写在前面,部分window由于是盗版影响,部分语音库存在问题,报错无效的类字符串或者没有注册的类
    那么可能是win7 tts语音有问题体,提醒可以去下载相应补丁
    链接:https://pan.lanzou.com/i0h951c


    import pyttsx3

    #初始化
    engine=pyttsx3.init()
    #test1
    engine.say('小说说的真好')
    engine.say('what are about you ?')
    engine.runAndWait()#运行

    #test2
    #朗读文本文档或pdf文档 将文字导入say
    engine.say('读取新建文本或者文档')
    with open(r'C:Usersv_weijianyeDesktop est.txt',encoding='utf-8')as f:
    engine.say(f.read())
    engine.runAndWait()

    # #test3
    #将声音保存在文件中
    eng = pyttsx3.init()
    eng.save_to_file('好好学习天天向上,死亡如风,常伴吾身,面对疾风吧' , 'test.mp3')
    eng.runAndWait()

    # test4
    # 改变音色
    engine=pyttsx3.init()
    voices=engine.getProperty('voices')
    for voice in voices:
    engine.setProperty('voice', voice.id)
    engine.say('The quick brown fox jumped over the lazy dog.')
    engine.runAndWait()

    # engine.setProperty('voice',voices[1].id)
    # engine.say('the quick brown fox jumped over the lazy dog.')
    # engine.runAndWait()

    #test5
    #改变语速(每分钟字数的整数语音速率)
    engine = pyttsx3.init()
    rate = engine.getProperty('rate')
    engine.setProperty('rate', rate+50)
    engine.say('The quick brown fox jumped over the lazy dog.')
    engine.runAndWait()

    #test6(浮点类型0-1之间)
    #改变音量
    engine = pyttsx3.init()
    volume = engine.getProperty('volume')
    engine.setProperty('volume', volume+0.25)
    engine.say('The quick brown fox jumped over the lazy dog.')
    engine.runAndWait()


    #test7将加载到的本地文件转化为声音后存储为mp3输出
    engine=pyttsx3.init()
    with open(r'C:Usersv_weijianyeDesktop腾讯灯塔.txt',encoding='utf-8') as f:
    engine.save_to_file(f.read(),f'灯塔.mp3')
    engine.runAndWait()
    print('finish')

    import pyttsx3
    engine=pyttsx3.init()
    with open(r'C:UsersAdministratorDesktop est.txt','r',encoding='GBK')as f:
    #'utf-8' codec can't decode byte 0xbd in position 0: invalid start byte 这里encoding 报错编码格式改为GBK 或者GB2312即可解决
    engine.save_to_file(f.read(),f'test.mp3')
    engine.runAndWait()
    print('end')

     
  • 相关阅读:
    在打工生涯中 规划自己的老板梦
    不屈不挠的战斗意志, 看创业者九大素质十条规则
    一条走不完的路,想创业先给自己几个问号
    摄影偶遇
    封顶法则:企业家抱负决定企业高度
    不批评、不责备、不抱怨、不攻击——经典沟通原则15条
    企业成败大关键,用情绪智力提升你的领导魅力
    穿汉服有感
    Oracle Advanced Security:Column Encryption Overhead
    在OEL5上安装配置Oracle Gird Control 10.2.0.5
  • 原文地址:https://www.cnblogs.com/yescarf/p/13749629.html
Copyright © 2011-2022 走看看