Recording synthesized text-to-speech to a file in Python

前端 未结 5 405
小蘑菇
小蘑菇 2020-12-16 20:03

I am attempting to find a way to take synthesized speech and record it to an audio file. I am currently using pyttsx as my text-to-speech library, but there isn\'t a mechani

5条回答
  •  再見小時候
    2020-12-16 20:31

    Here is an example which gives you access to the NSSpeechSynthesizer API

    #!/usr/bin/env python
    
    from  AppKit import NSSpeechSynthesizer
    import sys
    import Foundation
    
    
    if len(sys.argv) < 2:
       text = raw_input('type text to speak> ')
    else:
       text = sys.argv[1]
    
    nssp = NSSpeechSynthesizer
    ve = nssp.alloc().init()
    ve.setRate_(100)
    url = Foundation.NSURL.fileURLWithPath_('yourpath/test.aiff')
    ve.startSpeakingString_toURL_(text,url)
    

提交回复
热议问题