Jump to content

[SOLVED] Save voice into .mp3 file


Mingre
 Share

Recommended Posts

Hello, I got this somewhere but unfortunately I failed to save the link.

Is it possible to export the read text to a mp3 file? Thanks!

Example.au3

TTS.au3

; TTS.au3

; #FUNCTION# ====================================================================================================================
; Name...........: _StartTTS
; Description ...: Creates a object to be used with Text-to-Speak Functions.
; Syntax.........: _StartTTS()
; Parameters ....:
; Return values .: Success - Returns a object
; Author ........: bchris01

; Example .......: Yes
; ===============================================================================================================================
Func _StartTTS()
    Return ObjCreate("SAPI.SpVoice")
EndFunc   ;==>_StartTTS

; #FUNCTION# ====================================================================================================================
; Name...........: _SetRate
; Description ...: Sets the rendering rate of the voice. (How fast the voice talks.)
; Syntax.........: _SetRate(ByRef $Object, $iRate)
; Parameters ....: $Object        - Object returned from _StartTTS().
;                  $iRate         - Value specifying the speaking rate of the voice. Supported values range from -10 to 10
; Return values .:  None
; Author ........: bchris01
; Example .......: Yes
; ===============================================================================================================================
Func _SetRate(ByRef $Object, $iRate); Rates can be from -10 to 10
    $Object.Rate = $iRate
EndFunc   ;==>_SetRate

; #FUNCTION# ====================================================================================================================
; Name...........: _SetVolume
; Description ...: Sets the volume of the voice.
; Syntax.........: _SetVolume(ByRef $Object, $iVolume)
; Parameters ....: $Object        - Object returned from _StartTTS().
;                  $iVolume       - Value specifying the volume of the voice. Supported values range from 0-100. Default = 100
; Return values .:  None
; Author ........: bchris01
; Example .......: Yes
; ===============================================================================================================================
Func _SetVolume(ByRef $Object, $iVolume);Volume
    $Object.Volume = $iVolume
EndFunc   ;==>_SetVolume

; #FUNCTION# ====================================================================================================================
; Name...........: _SetVoice
; Description ...: Sets the identity of the voice used for text synthesis.
; Syntax.........: _SetVoice(ByRef $Object, $sVoiceName)
; Parameters ....: $Object        - Object returned from _StartTTS().
;                  $sVoiceName    - String matching one of the voices installed.
; Return values .:  Success - Sets object to voice.
;                   Failure - Sets @error to 1
; Author ........: bchris01
; Example .......: Yes
; ===============================================================================================================================
Func _SetVoice(ByRef $Object, $sVoiceName)
    Local $VoiceNames, $VoiceGroup = $Object.GetVoices
    For $VoiceNames In $VoiceGroup
        If $VoiceNames.GetDescription() = $sVoiceName Then
            $Object.Voice = $VoiceNames
            Return
        EndIf
    Next
    Return SetError(1)
EndFunc   ;==>_SetVoice

; #FUNCTION# ====================================================================================================================
; Name...........: _GetVoices
; Description ...: Retrives the currently installed voice identitys.
; Syntax.........: _GetVoices(ByRef $Object[, $Return = True])
; Parameters ....: $Object        - Object returned from _StartTTS().
;                  $bReturn       - String of text you want spoken.
;                  |If $bReturn = True then a 0-based array is returned.
;                  |If $bReturn = False then a string seperated by delimiter "|" is returned.
; Return values .:  Success - Returns an array or string containing installed voice identitys.
; Author ........: bchris01
; Example .......: Yes
; ===============================================================================================================================
Func _GetVoices(ByRef $Object, $bReturn = True)
    Local $sVoices, $VoiceGroup = $Object.GetVoices
    For $Voices In $VoiceGroup
        $sVoices &= $Voices.GetDescription() & '|'
    Next
    If $bReturn Then Return StringSplit(StringTrimRight($sVoices, 1), '|', 2)
    Return StringTrimRight($sVoices, 1)
EndFunc   ;==>_GetVoices

; #FUNCTION# ====================================================================================================================
; Name...........: _Speak
; Description ...: Speaks the contents of the text string.
; Syntax.........: _Speak(ByRef $Object, $sText)
; Parameters ....: $Object        - Object returned from _StartTTS().
;                  $sText         - String of text you want spoken.
; Return values .:  Success - Speaks the text.
; Author ........: bchris01
; Example .......: Yes
; ===============================================================================================================================
Func _Speak(ByRef $Object, $sText)
    $Object.Speak($sText)
EndFunc   ;==>_Speak
; Example.au3

#include <TTS.au3>

$Default = _StartTTS()
If Not IsObj($Default) Then
    MsgBox(0, 'Error', 'Failed create object')
    Exit
EndIf
_Speak($Default, 'Hello my name is Sam. I am the default voice. Here are the other voices you have to choose from.')
MsgBox(0, 'Voices installed', StringReplace(_GetVoices($Default, False), '|', @CRLF))

$aVoiceSelection = _GetVoices($Default)

$Mike = _StartTTS()
_SetVoice($Mike, 'Microsoft Mike')
If @error Then
    _Speak($Default, 'Mike is Not installed.')
    $Mike = False
EndIf

$Mary = _StartTTS()
_SetVoice($Mary, $aVoiceSelection[1])
If @error Then
    _Speak($Default, 'Mary is Not installed.')
    $Mary = False
EndIf

If IsObj($Mike) Then _Speak($Mike, 'Hello my name is Mike.')
If IsObj($Mary) Then _Speak($Mary, 'Hello my name is Mary.')

_SetRate($Default, 5)
_Speak($Default, 'This is Sam talking really really fast.')
_SetRate($Default, -5)
_Speak($Default, 'This is Sam talking slow.')

 

Edited by Mingre
Mark as solved.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...