knochenhans / tts_arranger

MIT License
6 stars 1 forks source link

Issue running demo - unable to find specified file #1

Open Hexatona opened 1 year ago

Hexatona commented 1 year ago

Hi there, I'm running the demo for this, and while the simple_writer is able to synthesize and write, when using the TTS_Writer I'm getting a file not found.

The code I'm running is:

items1 = []
items1.append(TTS_Item('This is a test:', 0))
items1.append(TTS_Item('This is another test:', 1))

items2 = []
items2.append(TTS_Item('Another test',  0))
items2.append(TTS_Item('This is getting boring!', 1))

chapter = []
chapter.append(TTS_Chapter(items1, 'Chapter 1'))
chapter.append(TTS_Chapter(items2, 'Chapter 2'))

project = TTS_Project(chapter, 'Project Title', 'Project Subtitle', author='Some Author')

# Add a cover image
project.add_image_from_url('https://coqui.ai/static/38a06ec53309f617be3eb3b8b9367abf/598c3/logo-wordmark.png')

writer = TTS_Writer(project, os.path.join(user_dir, 'tts_arranger_example_output/'), preferred_speakers=preferred_speakers)
writer.synthesize_and_write(project.author + ' - ' + project.title,'C:\\temp\\')

And I get this output:

Synthesizing project "Project Title".
Preprocessing items.
Initializing speech synthesizer.
 > tts_models/en/vctk/vits is already downloaded.
Synthesizing chapter 1 of 2.
Synthesizing item 1 of 4:
(0 => "p273", 0ms): This is a test:
Adding pause: 750ms:
Synthesizing item 3 of 4:
(1 => "p330", 0ms): This is another test:
Adding pause: 750ms:
Temp file added: C:\temp\uxx05nrp\tts_part_0.wav
Synthesizing project "Project Title" failed: [WinError 2] The system cannot find the file specified.

I specify the temp directory because I was getting the same error without specifying it and thought that might be the issue.

I should also note that I don't see the temp file being created either.

knochenhans commented 1 year ago

Hi, thanks for reporting! There was no checking if the temporary dir prefix is existing before creating the actual temp dir in it. This is fixed now, could you please check with the new release?

Hexatona commented 1 year ago

Hmm, when I run it with the new version, without specifying a temp directory I get this output:

File "C:\Users\aarendt\Miniconda3\envs\coquitts\lib\os.py", line 225, in makedirs
    mkdir(name, mode)
FileNotFoundError: [WinError 3] The system cannot find the path specified: ''

and if i specify a directory, i get this:

File "C:\Users\aarendt\Miniconda3\envs\coquitts\lib\os.py", line 225, in makedirs
    mkdir(name, mode)
FileExistsError: [WinError 183] Cannot create a file when that file already exists: 'C:\\temp\\'
knochenhans commented 1 year ago

That's because there was a bug in my bugfix 🙃 The updated version I just released should fix the problem, finally.

Hexatona commented 1 year ago

I feel bad about this - I'm wondering if it's a me problem 😅

I'm getting the same output as earlier.

no temp dir specified

Synthesizing chapter 1 of 2.
Synthesizing item 1 of 4:
(0 => "p273", 0ms): This is a test:
Adding pause: 750ms:
Synthesizing item 3 of 4:
(1 => "p227", 0ms): This is another test:
Adding pause: 750ms:
Temp file added: C:\Users\aarendt\AppData\LOCAL\Temp\tmp35l1fntm\tts_part_0.wav
Synthesizing project "Project Title" failed: [WinError 2] The system cannot find the file specified.

temp dir specified

Synthesizing chapter 1 of 2.
Synthesizing item 1 of 4:
(0 => "p273", 0ms): This is a test:
Adding pause: 750ms:
Synthesizing item 3 of 4:
(1 => "p227", 0ms): This is another test:
Adding pause: 750ms:
Temp file added: C:\temp\tmpvg2pkfod\tts_part_0.wav
Synthesizing project "Project Title" failed: [WinError 2] The system cannot find the file specified.

Alright - maybe we should change tack. I'll post the exact file I'm using to try to run this(just stright up '>python thisfile.py', and if you get the same error, good - if not... well, yes likely this is a me problem.

import os

from tts_arranger import TTS_Item, TTS_Simple_Writer, TTS_Chapter, TTS_Project, TTS_Writer

# Simple example using Simple Writer (using a simple list of TTS items), uses tts_models/en/vctk/vits by (default)

user_dir = 'C:\\temp\\'

tts_items = []

preferred_speakers = ['p273', 'p227']

tts_items.append(TTS_Item('This is a test', 0))  # Uses preferred speaker #0
tts_items.append(TTS_Item(length=2000))  # Insert pause
tts_items.append(TTS_Item('This is a test with another speaker and a fixed minimum length', 1, length=10000)) # Uses preferred speaker #1 and sets minimum length

# Create writer using our item list and prefered speakers and synthesize and save as mp3 audio
simple_writer = TTS_Simple_Writer(tts_items, preferred_speakers)
simple_writer.synthesize_and_write(os.path.join(user_dir, 'tts_arranger_example_output/test.mp3'))

# English example using tts_models/en/vctk/vits (with multispeaker support)

items1 = []
items1.append(TTS_Item('This is a test:', 0))
items1.append(TTS_Item('This is another test:', 1))

items2 = []
items2.append(TTS_Item('Another test',  0))
items2.append(TTS_Item('This is getting boring!', 1))

chapter = []
chapter.append(TTS_Chapter(items1, 'Chapter 1'))
chapter.append(TTS_Chapter(items2, 'Chapter 2'))

project = TTS_Project(chapter, 'Project Title', 'Project Subtitle', author='Some Author')

# Add a cover image
project.add_image_from_url('https://coqui.ai/static/38a06ec53309f617be3eb3b8b9367abf/598c3/logo-wordmark.png')

writer = TTS_Writer(project, os.path.join(user_dir, 'tts_arranger_example_output/'), preferred_speakers=preferred_speakers)
writer.synthesize_and_write(project.author + ' - ' + project.title,user_dir)
knochenhans commented 1 year ago

No worries, the things you pointed out clearly addressed problems in my path handling code so that was already helpful, thank you!

Looks like there are still some problems with how Windows paths are handled that relate to the original bug I tried to fix. I mostly do Python coding on Linux so I guess I never ran into these path-related corner cases. I’ll do more testing on my Windows machine and see what I can come up with.

knochenhans commented 1 year ago

@Hexatona, would you care to check using the debugger where exactly my code is hitting the error above with you? If you use vscode, you can just make a project for your test code and add "justMyCode": false to your launch.json file.

I suspect this his happening when the synthesized chapter audio is written to the temp file using scipy.io.wavfile.write, though I have no idea why this isn’t triggered for the first chapter in the example already. It almost seems the temp directory is getting deleted at some place for some reason.