Author Topic: how to choose randomly between text files and have TTS read them?  (Read 2637 times)

mrmauz

  • Guest
hello, total n00b here, also not a programmer at all but i need some tips and hints on a little project i have in mind.

i would like to make an italian port of the infamous ripley galactic KICS 4.1 because i just can't make it understand half of the phrases i pronounce... i'm afraid my italian accent it's too heavy for both the VA default and the windows Speech engines.

i've read how to install my native language speech engine and that's not a problem.

got some questions about the necessary modification i would need to do to the original profile.

let's say i manage to edit the spoken command in italian, that's the easy part and it only takes time, BUT i would like to change also the spoken audio files that come with KICS, and replace them instead with a list of .txt files that could be read from the TTS engine...

what's the proper way to edit the "play sound xxx.mp3" (or "play random sound from a list of .mp3") into a "read from xxx.txt" (or "read from a random list of .txt)
is there a way?

hope you can help me or show me a better way to achieve a similar goal
thanks in advance

Mauz

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: how to choose randomly between text files and have TTS read them?
« Reply #1 on: May 10, 2018, 10:52:55 AM »
You need to use the "Set a Text Value" action to read text from a file, which you can feed the "{TXTRANDOM:}" token with a list of files.

E.G.
Code: [Select]
Set Text [~textToSpeak] to [C:\My Files\{TXTRANDOM:file1;file2;anotherfile}.txt]
Say, '{TXT:~textToSpeak}'


Though for simple phrases I'd use randomized phrases in the "Say Something with Text-To-Speech" action instead; Phrases separated by a semicolon(";") will be picked from randomly:
Code: [Select]
Say, 'phrase one' or 'phrase two' or 'another phrase' or 'phrase with a [variable' or 'random] sub phrase'
was generated from
Code: [Select]
phrase one;phrase two;another phrase;phrase with a [variable;random] sub phraseAs you can see you can combine this with segments in square brackets to randomize parts of a sentence(the same syntax as dynamic command sections).

mrmauz

  • Guest
Re: how to choose randomly between text files and have TTS read them?
« Reply #2 on: May 10, 2018, 01:52:19 PM »
that is cool! gonna start working on it right now, thanks.
can i disturb you again should i encounter some more questions?
maybe i should change the name of the post to "can you help me doing stuff i have no idea how to do it"...

 :-[

Caio Martinelli

  • Newbie
  • *
  • Posts: 3
Re: how to choose randomly between text files and have TTS read them?
« Reply #3 on: December 18, 2020, 03:04:13 PM »
I know this is old, but google shows this topic as a result of the many ways I search for my question in the last many hours, so I ended up installing voiceattack and here to try solve a related question.

I hope someone can help

(The goal)
What I really need to do is

1 - Press a button
3 - Start keylogging my keyboard (to get text within a game in the foreground)
2 - Press a button
4 - Stop keylogging my keyboard and saves it
5 - TSS reads the text into a microphone input
6 - What i have typed goes to in-game conversation voice chat.

(The base problem)
This should be simple, but I'm having a hard time finding a way to do it all in the background without specific program text areas.

(My way to do it)

My idea to solve this was:

Use a program to make [1 ... 4] and save it to a .txt file and then use voiceattack to read that file through a virtual input microphone (I will probably use the VB cable for this) .

(The Voiceattack Problem)
Where in the program I put this:

Code: [Select]
"Set Text [~ textToSpeak] to [C:\ My Files\{TXTRANDOM: file1; file2; anotherfile}.txt]
Say, '{TXT: ~ textToSpeak}' "

I was using this to point on my .txt file:
Code: [Select]
"Set Text [~ textToSpeak] to [C:\Users\caiof\Desktop\{TXTRANDOM: MyTextToOutput}.txt]
Say, '{TXT: ~ textToSpeak}' "

I tried to put it in C and VB.net in advanced options, none worked.



I really think this is the best way to achieve the objetive if this problem is solved

Can someone please proceed with help or a tip if you think there is a better way?
.
Thanks a lot for your time!

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: how to choose randomly between text files and have TTS read them?
« Reply #4 on: December 18, 2020, 03:21:14 PM »
Have you read the documentation on the features you're trying to use? Press F1 while VoiceAttack has focus to open VoiceAttackHelp.pdf in your default PDF viewer.

If you're using a single text file, there's no need for the "{TXTRANDOM:}" token. There is no inline function involved in any of this either.


The "code" blocks show what your action list would look like, I.E. you need to add the appropriate actions to a command manually in order to replicate what is shown.

In this case you need a "Set a Text Value" action, set up to use the "Value from file/URI" option to get the contents of your text file, and a "Say Something with Text-To-Speech" action, in which you use the "{TXT:}" token to get the value of the variable set by the "Set a Text Value" action

If you set those up correctly, the action list for your command should look like this:
Code: [Select]
Set Text [~textToSpeak] to [C:\Users\caiof\Desktop\MyTextToOutput.txt]
Say, '{TXT:~textToSpeak}'

Caio Martinelli

  • Newbie
  • *
  • Posts: 3
Re: how to choose randomly between text files and have TTS read them?
« Reply #5 on: December 18, 2020, 03:59:30 PM »
I was sure that it was a code  ;D

Thanks a lot man

Now its working perfect, half of the problem until my general objetive and full problem related to VoiceAttack is solved, as a last question, i tried to get the text using this program to solve everything right now but it request that i type on a specific window on foreground to get a text as you can see below. Do you or someone who reads this know any way do avoid it? To just get the input until i press some key? This is my last question. Thanks again man.

Caio



Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: how to choose randomly between text files and have TTS read them?
« Reply #6 on: December 18, 2020, 04:20:28 PM »
There is currently no built-in method for getting arbitrary keystrokes or character input without requiring a specific field to have focus, no.

Such a feature has been requested.


The closest you can probably get, currently, is to set up individual commands for each and every key. However, that would not allow blocking keystrokes from getting through to the current application while typing your message, without also blocking them for normal use.

Caio Martinelli

  • Newbie
  • *
  • Posts: 3
Re: how to choose randomly between text files and have TTS read them?
« Reply #7 on: December 18, 2020, 05:02:13 PM »
Oh ok, it would be great to have the solution all in one program, in this case at least is well partially solved, I will try what you said setting up individual commands to each key as well as something probably involving AutoHotKey and some other programs (I need to do more research) to see what fits best in that specific part of the work to archieve the complete solution for now.

Thank you very much for your help man!