1
$\begingroup$

I wrote a program for practicing note identification on a guitar:

note1 = {"A.", "B", "C", "D", "E", "F", "G"};
note2 = {" Sharp", " Natural", " Flat"};
string = {"first  ", "second  ", "third  ", "fourth ", "fifth ", 
   "sixth "};

list = StringJoin[#] & /@ Tuples[{note1, note2}];
list2 = Flatten[
   Table[RandomSample[StringJoin[#] & /@ Tuples[{string, list}]], {i, 
     1, 1}]];
For[i = 1, i <= Length[list2], i++,
 Speak[list2[[i]]];
 Pause[2.5];
 ]

I do not have a Mathematica license, so I want to use Wolfram Cloud. The problem is that the server times out before the for-loop gets through the entire list. Is there anyway to send the speak command to the server, then have it send back the entire list in audio format?

$\endgroup$
1
  • 3
    $\begingroup$ If you don't have a Mathematica license, and Wolfram Cloud is not a solution for you, you can still use Wolfram Engine and Jupyter Notebook as a front-end, both free to install and use (some restrictions apply). $\endgroup$
    – rhermans
    May 23, 2022 at 9:30

1 Answer 1

3
+50
$\begingroup$

This works for me on Wolfram Cloud:

note1 = {"A.", "B", "C", "D", "E", "F", "G"};
note2 = {" Sharp", " Natural", " Flat"};
string = {"first  ", "second  ", "third  ", "fourth ", "fifth ", 
   "sixth "};

list = StringJoin[#] & /@ Tuples[{note1, note2}];
list2 = Flatten[
   Table[RandomSample[StringJoin[#] & /@ Tuples[{string, list}]], {i, 
     1, 1}]];
pauseTime = 2;(*in seconds*)
audio = AudioJoin[
   AudioPad[#, pauseTime] & /@ SpeechSynthesize /@ list2]

To speed the spoken part up, add AudioTimeStretch with an appropriate factor. I had to rewrite the code a bit, as Wolfram Cloud doesn't seem to like too many nested Map-functions. Adjust audioSpeed to taste:

Clear[note1,note2,string,list,list2,pauseTime,audio,audioSpeed];
note1 = {"A.", "B", "C", "D", "E", "F", "G"};
note2 = {" Sharp", " Natural", " Flat"};
string = {"first  ", "second  ", "third  ", "fourth ", "fifth ", 
   "sixth "};
   list = StringJoin[#] & /@ Tuples[{note1, note2}];
list2 = Flatten[
   Table[RandomSample[StringJoin[#] & /@ Tuples[{string, list}]], {i, 
     1, 1}]];
pauseTime = 2;(*in seconds*)
audioSpeed=0.9;(*Values < 1 for speeding up*)
   speedaudio=AudioJoin[Riffle[AudioTimeStretch[SpeechSynthesize[#],audioSpeed,Method->"Speech"]&/@list2,AudioGenerator["Silence",pauseTime]]]
$\endgroup$
4
  • $\begingroup$ This is great thanks! The speaking seems a little slow though, is there any way to speed those parts up? $\endgroup$
    – ngc1300
    May 23, 2022 at 13:40
  • $\begingroup$ Do you mean the pause between each called note and string is too long or the spoken part itself is too sluggish? $\endgroup$
    – rowsi
    May 23, 2022 at 14:09
  • $\begingroup$ The spoken part is a bit too sluggish $\endgroup$
    – ngc1300
    May 23, 2022 at 14:28
  • $\begingroup$ Updated my answer with a solution. $\endgroup$
    – rowsi
    May 23, 2022 at 15:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.