AutoHotkey Community

It is currently May 26th, 2012, 9:29 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: August 4th, 2009, 6:56 pm 
Offline

Joined: March 16th, 2009, 1:27 am
Posts: 9
Hello and thank you for taking a look at this post.

I first want to thank all those involved with the creation and continued development of autohotkey. This program has greatly helped in my time management through automation.

Now on to the challenge.

I have a program called "Swifttalker" that (amongst other things) gives me the capability to convert txt files into wav files so I can listen to the words in the file aloud. A text to speech program. It makes this possible through manual efforts (manual clicking) and from command line submission.

I have been using the manual side for a while now and it works great for one or two files at a time.

Unfortunately I now have 219 pages (files) to convert and don't want to be sitting in front of my computer for days to complete this task.

So I started writing a script that would automate this process.

The challenge I'm having is with the loop (possibly other areas too).

If anyone would be willing to help it would be greatly appreciated. By the way, i have search the forum prior to this post to find and answer and found many answer regarding loops. Unfortunately, I did not find any related to this specific challenge.

Any and all suggestions are welcome. Thank you in advance for any actions and/or suggestions you may have.

Short script that has been tested and works:

Code:
^#!s:: ;;swifttalker speaks
Run, swift -n Callie -f "g:\ebook\adwords_beginning of page_008.txt" -o g:\ebook\wav_version\adwords_page_008.wav
return


Here is the current loop script that doesn't work:

Code:
Esc::ExitApp   ;This exits the script whenever you press Escape
^#!s:: ;;swifttalker converts txt to wav
#SingleInstance, Force
#NoEnv
text_to_wav_folder = G:\ebook\ ;Source text_to_wav_folder
wav_folder = %text_to_wav_folder%\wav_version\ ;Destination folder
IfExist, %wav_folder%\*.* ;If the wav files already exists in wav_folder,
   FileDelete, %wav_folder%*.* ;deletes any files from earlier converts

;Loop, %text_to_wav_folder%*.txt, , 0 ;Find all txt files, do not include subfolders
Loop, %ItemCount%
{
    Run, swift -n Callie -f "%text_to_wav_folder%%A_LoopFileName%.txt" -o %wav_folder%%A_LoopFileName%.wav
   Sleep, 200000
   If ( ItemCount <= A_Index )
       break  ; Terminate the loop
}
MsgBox, Txt To Wav Coversion Is Done...
ExitApp



Last two things:

1. Having the ability to stop a run away loop like the below code included shows would be wonderful (I've already had to shut my computer down several time due to this one):


Code:
Esc::ExitApp   ;This exits the script whenever you press Escape
^#!s:: ;;swifttalker converts txt to wav
#SingleInstance, Force
#NoEnv
text_to_wav_folder = G:\ebook\ ;Source text_to_wav_folder
wav_folder = %text_to_wav_folder%\wav_version\ ;Destination folder
IfExist, %wav_folder%\*.* ;If the wav files already exists in wav_folder,
   FileDelete, %wav_folder%*.* ;deletes any files from earlier converts

;Loop, %text_to_wav_folder%*.txt, , 0 ;Find all txt files, do not include subfolders
Loop, %ItemCount%
{
    Run, swift -n Callie -f "%text_to_wav_folder%%A_LoopFileName%.txt" -o %wav_folder%%A_LoopFileName%.wav
   Sleep, 200000
   If ( ItemCount <= A_Index )
       break  ; Terminate the loop
}
MsgBox, Txt To Wav Coversion Is Done...
ExitApp



And last one:

2. Replacing the msgbox at the end with a tooltip balloon that displays for a few seconds then goes away would bring about the quan (watch Jerry McGuire movie to find out; although I most likely misspelled it)

Thanks again and make sure you have a fantastic day!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 5th, 2009, 5:01 am 
Offline

Joined: March 16th, 2009, 1:27 am
Posts: 9
I think I have the last two items handled.

So if someone would help me out with the loop ... that would be great.

The part that I seem to be having difficulty with is the runwait line and the filemove line.

what I would like to see happen:
I need the the runwait line to use one text file at a time from the text_to_wav_folder, convert it to wav using the swifttalker command statement, move the original txt file to the converted folder, and place the finished wav file in the wav_folder.

what is actually happening:
first file is chosen ?, black command page flashes on the screen, and no wav file is created. Then the filemove move all the files from the text_to_wav_folder to the converted_folder at one time instead of one at a time. Then the loop ends and script ends (according to the traytips).

Here is updated code:

Code:
Esc::ExitApp   ;This exits the script whenever you press Escape
^#!s:: ;;swifttalker converts txt to wav
SetBatchLines, -1
#SingleInstance, Force
#NoEnv

text_to_wav_folder = g:\ebook\ ;Source text_to_wav_folder
wav_folder = %text_to_wav_folder%wav_version\ ;Destination folder
converted_folder = %text_to_wav_folder%converted\ ;move orginal file here after conversion

IfExist, %wav_folder%\*.* ;If the wav files already exists in wav_folder,
   FileDelete, %wav_folder%*.* ;deletes any files from earlier converts

Hotkey, #space, myLabel ; a hotkey you can use to stop the loop, for instance Win-Space

stopper = 0 ; a variable which can be asked in the loop whether to stop or to go on, initialised with 0

Loop, %text_to_wav_folder%*.txt
{
   TrayTip, Txt To Wav, Starting To Processing Page %A_Index%, 20, 1

    OutputVar := SubStr(A_LoopFileName, 1, StrLen(A_LoopFileName) - ((A_LoopFileExt <> "") ? (StrLen(A_LoopFileExt) + 1) : 0))
   
   RunWait, swift -n Callie -f "%text_to_wav_folder%%A_LoopFileName%" -o %wav_folder%%OutputVar%.wav
   
   TrayTip, Txt To Wav, Moving txt files to converted folder now, 20, 1
   Sleep, 10000 ; sleep for 10 seconds

   FileMove, %text_to_wav_folder%, %converted_folder%, 1
   
   TrayTip, Txt To Wav, Finished Processing Page %A_Index% `n Starting Next Page, 20, 1
   Sleep, 10000 ; sleep for 10 seconds
   
   If ( ItemCount <= A_Index )
      break  ; Terminate the loop
      
   if (stopper = 1)
      break
}

TrayTip, Txt To Wav, Txt To Wav Coversion Is Done..., 20, 1

myLabel: ; the hotkey was pressed, let's set the variable which is asked in the loop
stopper = 1
return


Thank you and have a fantastic day!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 5th, 2009, 1:36 pm 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
Some remarks:

- Instead of Outputvar =... I suggest you look at the SplitPath command it is much easier to understand in my opinion.

- Your filemove command seems to move the entire folder, you are missing the file you just processed? So it should probably be
Code:
FileMove, %text_to_wav_folder%%A_LoopFileName%, %converted_folder%, 1

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 5th, 2009, 6:43 pm 
Offline

Joined: March 16th, 2009, 1:27 am
Posts: 9
@HugoV

Thank you for the reply.

I attempted SplitPath, which I was unable to get to function like OutputVar due to how it works with wildcards (* and ?). In the remarks section of SplitPath it says:

Quote:
Remarks
Any of the output variables may be omitted if the corresponding information is not needed.

If InputVar contains a filename that lacks a drive letter (that is, it has no path or merely a relative path), OutDrive will be made blank but all the other output variables will be set correctly. Similarly, if there is no path present, OutDir will be made blank; and if there is a path but no file name present, OutFileName and OutNameNoExt will be made blank.

Actual files and directories in the file system are not checked by this command. It simply analyzes the string given in InputVar.

Wildcards (* and ?) and other characters illegal in filenames are treated the same as legal characters, with the exception of colon, backslash, and period (dot), which are processed according to their nature in delimiting the drive letter, directory, and extension of the file.


So that is why I went with OutputVar. It also is the only one that I could get to work in displaying the outcome correctly in a msgbox while testing.

If you know of a way that I over looked ... please share.


Also, in regards to the FileMove:

Thank you. I don't know how I missed that. I've been working on this issue for many hours. Perhaps a break would help. Anyway thank you again.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 5th, 2009, 8:39 pm 
Offline

Joined: November 24th, 2005, 8:16 am
Posts: 851
trstone,

It is hard to debug like this.
You should test one component at a time.
1. I dont see why you cannot use SplitPath to extract the the path components from A_FileLongPath

2. Comment out your FileMove and everything else that is not related to your problem at hand

3. If I got this correctly, your WAV is not generated? If thats the problem, than your command line call is invalid. MsgBox it and see what is the problem there. Maybe it cant find your swift talker command line EXE or maybe it cannot access your output folder or something else

4. Not related to your problem, but I noticed an extra slash here
Code:
IfExist, %wav_folder%\*.* ;If the wav files already exists in wav_folder,


5. You can use the HIDE option to hide that black console screen.

6. Why would you want to sleep for 10 seconds after each run?

7. If you submit a script asking for help, you should try and compact it as much as possible - remove what is not needed for your problem - this process alone can usually help you solve things.

_________________
Sector-Seven - Freeware tools built with AutoHotkey


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 9th, 2009, 3:27 am 
Offline

Joined: March 16th, 2009, 1:27 am
Posts: 9
@Icarus

Thank you for taking the time to reply.

To answer you:

0. Testing one at a time:

You are absolutely correct. I figured that out after my first post. So that is what I did between the first and the last post (that being tested one item at a time).

1. SplitPath:

I don't know how to use SplitPath. I also don't really understand "OutputVar" either. I found that line of code in someone else's example.

2. Comment out:

I did while I was testing. I only posted the whole script on my last post, for anyone that is attempting to help me. I figured they could benefit from seeing the whole script instead of several little parts).

3. Command line call:

Your right, it is invalid or not functioning correctly. I did attempt to msgbox it and every thing shows in the msgbox correctly. As far as finding the swifttalk command line exe and the folder output, it worked when I manually typed the argument into the command line. This is the part that I currently don't understand and need help with.

4. extra slash:

Yes your right. Thank you. Fixed it.

5. Hide option:

Yes, I believe I will use it once this script is fully functional.

6. Sleep:

These were left over from my testing.

7. Compact & remove:

O.k. I can re-post only the command line loop if necessary.

Again thank you and have a fantastic day!


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], BrandonHotkey and 59 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group