feat: implement using text from the clipboard as input
This commit is contained in:
parent
266c94aa8c
commit
90847b0b68
3 changed files with 31 additions and 5 deletions
11
README.md
11
README.md
|
@ -74,6 +74,8 @@ Running the program without arguments will use the demo text `tongue-twister.txt
|
|||
$ python tts.py # will use default arguments
|
||||
```
|
||||
|
||||
### Providing text inputs
|
||||
|
||||
You can pass a string as first argument:
|
||||
|
||||
```bash
|
||||
|
@ -89,6 +91,15 @@ $ python tts.py --input_file demo/tongue-twister.txt
|
|||
$ python tts.py -i demo/tongue-twister.txt
|
||||
```
|
||||
|
||||
You can also use the text stored in your clipboard (i.e., copied text). Select a text from anywhere (e.g., your web browser), copy it with `<ctrl>+C` or the context menu, then use the flag `--clipboard`:
|
||||
|
||||
```bash
|
||||
$ python tts.py --clipboard
|
||||
|
||||
# or shorter...
|
||||
$ python tts.py -c
|
||||
```
|
||||
|
||||
### Voices
|
||||
|
||||
Optionally, you can indicate a voice you want to use with the `--voice` flag. See [all voices available](https://huggingface.co/hexgrad/Kokoro-82M/blob/main/VOICES.md).
|
||||
|
|
|
@ -4,3 +4,4 @@ python-vlc
|
|||
tqdm
|
||||
argparse
|
||||
torch
|
||||
pyperclip
|
14
tts.py
14
tts.py
|
@ -8,6 +8,7 @@ from kokoro import KPipeline
|
|||
import soundfile as sf
|
||||
import vlc
|
||||
from tqdm import tqdm
|
||||
import pyperclip
|
||||
|
||||
# Disable all warnings
|
||||
warnings.filterwarnings("ignore")
|
||||
|
@ -45,6 +46,13 @@ def parse_args():
|
|||
default="demo/tongue-twister.txt",
|
||||
help="Path to the input text file",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--clipboard",
|
||||
"-c",
|
||||
required=False,
|
||||
action="store_true",
|
||||
help="Use text from the clipboard (i.e., copied text)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--device",
|
||||
"-d",
|
||||
|
@ -98,6 +106,12 @@ def main():
|
|||
|
||||
# filename argument
|
||||
if args.input_text == "":
|
||||
if args.clipboard:
|
||||
# use copied text
|
||||
print('Using copied text as input...')
|
||||
text = pyperclip.paste()
|
||||
name = 'copied'
|
||||
else:
|
||||
file_path = args.input_file
|
||||
directory, file_name = os.path.split(file_path)
|
||||
name = '.'.join(file_name.split('.')[:-1])
|
||||
|
|
Loading…
Reference in a new issue