0

pico2wave
Wish to input a text file into pico2wave.

Something like this ...

pico2wave 'read a file'

My entire code

sudo apt update &&

dependencies=(calibre sox libttspico-utils) for i in ${dependencies[@]}; do sudo apt install $i -y; done;

Name="Why-Did-John-Nash-Stop-His-Medication" Address="https://www.researchgate.net/profile/Peter-Weiden/publication/7757848_Why_Did_John_Nash_Stop_His_Medication/links/5dff8196299bf10bc370696a/Why-Did-John-Nash-Stop-His-Medication.pdf"

wget --header="User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_0) AppleWebKit/600.1.17 (KHTML, like Gecko) Version/8.0 Safari/600.1.17"
$Address

ebook-convert $Name.pdf
$Name.txt

cat $Name.txt

pico2wave --lang=en-GB --wave=$Name.wav < $Name.txt

play $Name.wav

abc
  • 116

3 Answers3

0

Bug : 2015 (8 year old bug)

enter image description here

Bug #1468771

https://bugs.launchpad.net/ubuntu/+source/svox/+bug/1468771]

enter image description here

abc
  • 116
0

Dissemble file, Cleanup Grammar

sudo apt update &&

dependencies=(calibre sox libttspico-utils) for i in ${dependencies[@]}; do sudo apt install $i -y; done;

Name="Why-Did-John-Nash-Stop-His-Medication"

Address="https://www.researchgate.net/profile/Peter-Weiden/publication/7757848_Why_Did_John_Nash_Stop_His_Medication/links/5dff8196299bf10bc370696a/Why-Did-John-Nash-Stop-His-Medication.pdf"

wget --header="User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_0) AppleWebKit/600.1.17 (KHTML, like Gecko) Version/8.0 Safari/600.1.17"
$Address

ebook-convert $Name.pdf
$Name.txt

while IFS= read -r Line; do

clear

echo "$Line" > file.tmp;

aspell -c file.tmp;

diction --quiet file.tmp;

String=$(cat file.tmp)

clear

echo "$String"

pico2wave --lang=en-GB --wave=temp.wav "$String";

aplay --quiet temp.wav

clear

done < "$Name.txt"

abc
  • 116
0

you can use the code below to efficiently convert any length of text into audio with pico2wave; the script splits the input text into segments of maximum length 3500words, then converts each segment into audio, finally the segments are concatenated into the final audio.mp3 file. Enjoy!! (Note: you should follow up the requirements of the pyrubberband lib especially if you want to tune tune the output by stretching, pitch-shifting,....)

    import os
    import subprocess
    from pydub import AudioSegment
    import soundfile as sf
    import pyrubberband as pyrb
    import subprocess
    # Not the requirements of pyrb (sudo apt install libttspico-utils sox)
    # pip install numpy Audiosegment pysox sox sndfile
def process_text_segment(text_segment, output_folder, segment_index):
    # Use pico2wave for audio generation
    wav_output_path = os.path.join(output_folder, f&quot;audio{segment_index}.wav&quot;)
    wav_output_path1 = os.path.join(output_folder, f&quot;audio{segment_index}.wav&quot;)
    subprocess.run(['pico2wave', '-w', wav_output_path, '-l', 'en-GB', text_segment])

    # Use pydub for audio processing
    audio = AudioSegment.from_wav(wav_output_path)
    duration = audio.duration_seconds

    # Additional processing steps if needed
    y, sr = sf.read(wav_output_path)
    # Play back at extra low speed
    y_stretch = pyrb.time_stretch(y, sr, 0.73)
    sf.write(wav_output_path1, y_stretch, sr, format='wav')
    # Play back extra low tones
    y, sr = sf.read(wav_output_path1)
    y_shift = pyrb.pitch_shift(y, sr, 1.5)
    sf.write(wav_output_path1, y_shift, sr, format='wav')
    sound = AudioSegment.from_wav(wav_output_path1)
    sound = sound + 12

    # Convert the processed audio to MP3
    mp3_output_path = os.path.join(output_folder, f&quot;audio{segment_index}.mp3&quot;)
    sound.export(mp3_output_path, format=&quot;mp3&quot;)

    # Clean up temporary WAV files
    os.remove(wav_output_path)
    os.remove(wav_output_path1)

    return mp3_output_path

def concatenate_audio_segments(output_folder, segment_count, mp3_output_path):
    # Concatenate audio segments
    segments = [AudioSegment.from_mp3(os.path.join(output_folder, f&quot;audio{i}.mp3&quot;)) for i in range(1, segment_count + 1)]
    final_audio = sum(segments)

    # Export the final concatenated audio to MP3
    final_audio.export(mp3_output_path, format=&quot;mp3&quot;)

    # Clean up intermediate audio segments
for i in range(1, segment_count + 1):
        os.remove(os.path.join(output_folder, f&quot;audio{i}.mp3&quot;))

def process_large_text(input_file_path, output_folder):
    with open(input_file_path, &quot;r&quot;) as file:
        text_content = file.read()

    # Split text content into segments of maximum 3500 words
    word_limit = 3500
    text_segments = [text_content[i:i+word_limit] for i in range(0, len(text_content), word_limit)]

    segment_count = len(text_segments)

    for i, text_segment in enumerate(text_segments, start=1):
        process_text_segment(text_segment, output_folder, i)

    # Concatenate audio segments
    mp3_output_path = os.path.join(output_folder, &quot;audio.mp3&quot;)
    concatenate_audio_segments(output_folder, segment_count, mp3_output_path)

    print(f&quot;Audio generated and saved to {mp3_output_path}&quot;)

# Example usage:
input_file_path = &quot;path/to/your/input/file.txt&quot;
output_folder = &quot;path/to/your/output/folder&quot;
process_large_text(input_file_path, output_folder)

noisefloor
  • 1,086