shellrosfestival

Writing a shell script to generate wave files


I was looking at writing a script to convert the contents of a .txt file to .wav files.

The command that currently does is :

text2wave textFileName.txt -o wavFileName.wav

So, pretty simple command. It looks at what's inside the .txt file and converts it all to a .wav file. But what I would like to do is have just one .txt that contains a number of lines and each of those lines would be converted to a .wav file. For example : line 0, line 1, line 2, ... to be converted into 0.wav, 1.wav, 2.wav, ... etc

Any ideas on how to achieve this? I'm also open to different approaches.


Solution

  • #!/bin/bash
    
    i=1
    filename=/path/to/text/file
    
    while read -r line
    do
        echo $line > somefile.txt
        text2wave somefile.txt -o $i.wav
        i=$((i+1))
    
    done < "$filename"
    

    I think this would do your job of extracting each line and converting into respective .wav file.