Error during file conversion

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
WantToKnow
Posts: 64
Joined: 28 Mar 2020, 08:46

Error during file conversion

14 Apr 2024, 08:08

Why do I get an error message when I try to convert the wav file to mp3 format?

Code: Select all

LinePause := "This is a break."
FileSelectFile, SelectedFile,, %A_ScriptDir%,Select File ,*.txt
If (ErrorLevel)
    return

Loop % SelectedFile
 strFileName := strSplit(A_LoopFileName, ".txt")[1]

FileRead, filecontent, %SelectedFile%

lineCount := 0
Loop, Parse, fileContent, `n
    lineCount++

TextZeilenAnzahl := strSplit(fileContent , "`n").length()

strWav := A_Yday "_" (A_hour*60 + A_min) "_" strFileName ".wav"
strMP3 := A_Yday "_" (A_hour*60 + A_min) "_" strFileName ".mp3"

spVoice := ComObjCreate("SAPI.SpVoice")
spVoice.Volume := 100 
spVoice.Rate := -3
spVoice.Voice := spVoice.GetVoices().Item(0) ; Set language
spVoice.AllowAudioOutputFormatChangesOnNextSet := 1

AllVoices := []
Loop, % spVoice.GetVoices.Count
{
    Name := spVoice.GetVoices.Item(A_Index-1).GetAttribute("Name")	; 0 based
    VoiceList .= A_Index - 1 "`t" Name "`n"   ; Nullbasiert deshalb: A_Index - 1
    AllVoices.push(Name)
}

InputBox, output, Choose voice,%VoiceList% ,, 400,400, 600, 50,,

If (ErrorLevel)
    return
spVoice.Voice := spVoice.GetVoices().Item(4) 
spStream := ComObjCreate("SAPI.SpFileStream")
SpStream.Open(strWav,3,1) 

spVoice.AudioOutputStream := spStream
loop %  strSplit(fileContent , "`n").length()   ; lineCount
{
spVoice.Volume := 100 ;
FileReadLine, LineContent, %SelectedFile%, A_Index
spVoice.Speak(LineContent) 
spVoice.Volume := 0  
spVoice.Speak(LinePause)
}

spVoice.AudioOutputStream.Close()


; No matter if I want to convert the wav file with lame.exe or ffmpeg.exe, the error occurs here:
RunWait, ffmpeg.exe -i "%strWav%" "%strMP3%"   ,, Hide ; Error here
RunWait, lame.exe -V2 "%strWav%" "%strMP3%",, Hide ; Error here

The error does not occur if I write the conversion commands into an extra function and execute it.
User avatar
mikeyww
Posts: 27009
Joined: 09 Sep 2014, 18:38

Re: Error during file conversion

14 Apr 2024, 08:13

Three suggestions are below.
  1. Remove all of the code except the conversion statement that you wish to test.
  2. Before the conversion, use FileExist to determine whether each of the two files exists.
  3. Post a screenshot of your error message.
If the script works, then you can determine which additional lines "break" the script, because you can add a couple of lines at a time and then retest.

I don't know whether the SpStream requires closing, but your script does not appear to close it.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], Descolada, FanaticGuru, Google [Bot], IfThenElse, LuckyJoe and 242 guests