Opentx Automated SAPI5 Voice Generator
Hey fellow OpenTX users!
I've been procrastinating whilst writing up my thesis, at the end of finishing up a rather long Matlab script I thought wouldn't it be great to be able to use Matlab to generate and save SAPI5 voice packs for my favorite TX, the FrSky Taranis.
Starting off with an Excel spreadsheet containing a list of the text to be read, the directory structure and the file name, this was imported into Matlab 2010 x32 (yep, it is the 32bit version, I have only been able to find a x32 version of the dll required for this script to work, I simply don't have enough time to procrastinate long enough to write my own x64 version). Then set up a few variables and a small looping script to take the text, file name and directory, read out the text in your favourite voice flavour then save the files into a new folder.
The script is as follows: rting off with an Excel spreadsheet containing a list of the text to be read, the directory structure and the file name, this was imported into Matlab 2010 x32 (yep, it is the 32bit version, I have only been able to find a x32 version of the dll required for this script to work, I simply don't have enough time to procrastinate long enough to write my own x64 version). Then set up a few variables and a small looping script to take the text, file name and directory, read out the text in your favourite voice flavour then save the files into a new folder.
The script is as follows:
rting off with an Excel spreadsheet containing a list of the text to be read, the directory structure and the file name, this was imported into Matlab 2010 x32 (yep, it is the 32bit version, I have only been able to find a x32 version of the dll required for this script to work, I simply don't have enough time to procrastinate long enough to write my own x64 version). Then set up a few variables and a small looping script to take the text, file name and directory, read out the text in your favourite voice flavour then save the files into a new folder.
The script is as follows:
Code:
% Set up the initial parameters clear all;close all; load('TaranisVoiceData.mat'); Fs = 32000; N = 228; R = 2; Voice = 3; FileName = 2; Directory = 1; Speed = 0; %range goes from -5 to 5 Nbits = 16; % Extract all words, file paths and file names for R = 2:N % the first one is a string if R == 1 VoiceList{R-1,Voice} = cellstr(textdata(R,Voice)); % use this for cells that contain 'strings' VoiceList{R-1,FileName} = cellstr(textdata(R,FileName)); VoiceList{R-1,Directory} = cellstr(textdata(R,Directory)); else % the next 2 to 110 are numbers if R >= 2 if R <= 110 VoiceList{R-1,Voice} = num2str(textdata{R,Voice}); % use this for cells that contain numbers VoiceList{R-1,FileName} = num2str(textdata{R,FileName}); VoiceList{R-1,Directory} = num2str(textdata{R,Directory}); elseif R > 110 VoiceList{R-1,Voice} = num2str(textdata{R,Voice}); % use this for cells that contain numbers VoiceList{R-1,FileName} = num2str(textdata{R,FileName}); VoiceList{R-1,Directory} = num2str(textdata{R,Directory}); end end end end %% Now to convert the text into speech and save Y=1; for Y=1:N if Y==227 break end VoiceTemp = VoiceList(Y,3); w = tts(char(VoiceTemp),'VW Kate',Speed,Fs); currentPath = pwd; % Get the current working directory [~,~,~] = mkdir(strcat(currentPath,'\SOUNDS'),'EN'); % make a new directory to store the files in ../EN & ../EN/SYSTEM [~,~,~] = mkdir(strcat(currentPath,'\SOUNDS\EN'),'SYSTEM'); % make a new directory to store the files in ../EN & ../EN/SYSTEM currentPath = strcat(currentPath,'\',VoiceList{Y,Directory},'\',VoiceList{Y,FileName}); % get the full file path SaveToHere = currentPath; % store full file path in temp variable % Save the file wavwrite(w,Fs,Nbits,currentPath); Y %counter to monitor progress end
The files are available here:
- TaranisVoiceData.mat
- This data file which contains the filenames, paths and default spoken text
- taranis_voiceGen.m
- The Matlab script - the script requires an x86 (32-bit) version of Matlab to run
- Taranis%20HQ%20SOUNDS.rar
- Contains all outputs from the script tts.m
Thanks to Siyi Dend who wrote the initial TTS script used in this release.
One last thing, to get a list of all the voices that you have available on your computer system just open up Matlab, open the working directory where you have saved the files downloaded from the section above, then in the console type in:
tts('','List');
Matlab will print out a list of all available voices on your PC. You can see in the script file I have used the 'VW Kate' SAPI5 voice pack, if you remove the 'VW Kate' and make it like this:
w = tts(char(VoiceTemp),'',Speed,Fs);
the script will use the default terrible Microsoft Mike or Anna voice, which is rather deplorable, so jump online and Google free SAPI5 voices, there are plenty to be found. See the figure below for an example list.
So with all of that out of the way, I hope that this script may become of use to someone in the community.
Let me know if there are any bugs and I'll try to fix them when I get another opportunity to procrastinate =)
Cheers & happy flying,
L