@@ -43,6 +43,7 @@ static uint8_t AudioPlayer_InitVolume = AUDIOPLAYER_VOLUME_INIT;
4343static void AudioPlayer_Task (void *parameter);
4444static void AudioPlayer_HeadphoneVolumeManager (void );
4545static char **AudioPlayer_ReturnPlaylistFromWebstream (const char *_webUrl);
46+ static char **AutioPlayer_ReturnPlaylistFromTextToSpeech (const char *_textToInsert);
4647static int AudioPlayer_ArrSortHelper (const void *a, const void *b);
4748static void AudioPlayer_SortPlaylist (const char **arr, int n);
4849static void AudioPlayer_SortPlaylist (char *str[], const uint32_t count);
@@ -624,6 +625,12 @@ void AudioPlayer_Task(void *parameter) {
624625 if (gPlayProperties .playMode == WEBSTREAM || (gPlayProperties .playMode == LOCAL_M3U && gPlayProperties .isWebstream )) { // Webstream
625626 audioReturnCode = audio->connecttohost (*(gPlayProperties .playlist + gPlayProperties .currentTrackNumber ));
626627 gPlayProperties .playlistFinished = false ;
628+ } else if (gPlayProperties .playMode == TEXT_TO_SPEECH) {
629+ audioReturnCode = true ; // is handled later
630+ gPlayProperties .tellCustomText = true ;
631+ gPlayProperties .currentSpeechActive = true ;
632+ gPlayProperties .lastSpeechActive = true ;
633+ gPlayProperties .playlistFinished = false ;
627634 } else if (gPlayProperties .playMode != WEBSTREAM && !gPlayProperties .isWebstream ) {
628635 // Files from SD
629636 if (!gFSystem .exists (*(gPlayProperties .playlist + gPlayProperties .currentTrackNumber ))) { // Check first if file/folder exists
@@ -657,6 +664,8 @@ void AudioPlayer_Task(void *parameter) {
657664 } else {
658665 Audio_setTitle (" Webradio" );
659666 }
667+ } else if (gPlayProperties .tellCustomText ) {
668+ Audio_setTitle (" Text To Speech" );
660669 } else {
661670 if (gPlayProperties .numberOfTracks > 1 ) {
662671 Audio_setTitle (" (%u/%u): %s" , gPlayProperties .currentTrackNumber +1 , gPlayProperties .numberOfTracks , *(gPlayProperties .playlist + gPlayProperties .currentTrackNumber ));
@@ -719,10 +728,32 @@ void AudioPlayer_Task(void *parameter) {
719728 }
720729 }
721730
731+ // Handle custom text
732+ if (gPlayProperties .tellCustomText ) {
733+ gPlayProperties .tellCustomText = false ;
734+ bool speechOk;
735+ String customText = " " ;
736+ if (gPlayProperties .playMode == TEXT_TO_SPEECH){
737+ customText = *(gPlayProperties .playlist );
738+ } else {
739+ customText = gPrefsSettings .getString (" customText" , " " );
740+ }
741+ #if (LANGUAGE == DE)
742+ speechOk = audio->connecttospeech (customText.c_str (), " de" );
743+ #else
744+ speechOk = audio->connecttospeech (customText.c_str (), " en" );
745+ #endif
746+ if (!speechOk) {
747+ System_IndicateError ();
748+ }
749+ }
750+
722751 // If speech is over, go back to predefined state
723752 if (!gPlayProperties .currentSpeechActive && gPlayProperties .lastSpeechActive ) {
724753 gPlayProperties .lastSpeechActive = false ;
725- if (gPlayProperties .playMode != NO_PLAYLIST) {
754+ if (gPlayProperties .playMode == TEXT_TO_SPEECH) {
755+ gPlayProperties .playMode = NO_PLAYLIST;
756+ } else if (gPlayProperties .playMode != NO_PLAYLIST) {
726757 xQueueSend (gRfidCardQueue , gPlayProperties .playRfidTag , 0 ); // Re-inject previous RFID-ID in order to continue playback
727758 }
728759 }
@@ -835,7 +866,11 @@ void AudioPlayer_TrackQueueDispatcher(const char *_itemToPlay, const uint32_t _l
835866 gPlayProperties .currentTrackNumber = _trackLastPlayed;
836867 char **musicFiles;
837868
838- if (_playMode != WEBSTREAM) {
869+ if (_playMode == WEBSTREAM) {
870+ musicFiles = AudioPlayer_ReturnPlaylistFromWebstream (filename);
871+ } else if (_playMode == TEXT_TO_SPEECH) {
872+ musicFiles = AutioPlayer_ReturnPlaylistFromTextToSpeech (filename); // no modification needed
873+ } else {
839874 if (_playMode == RANDOM_SUBDIRECTORY_OF_DIRECTORY) {
840875 filename = SdCard_pickRandomSubdirectory (filename); // *filename (input): target-directory // *filename (output): random subdirectory
841876 if (filename == NULL ) { // If error occured while extracting random subdirectory
@@ -846,8 +881,6 @@ void AudioPlayer_TrackQueueDispatcher(const char *_itemToPlay, const uint32_t _l
846881 } else {
847882 musicFiles = SdCard_ReturnPlaylist (filename, _playMode);
848883 }
849- } else {
850- musicFiles = AudioPlayer_ReturnPlaylistFromWebstream (filename);
851884 }
852885
853886 // Catch if error occured (e.g. file not found)
@@ -857,6 +890,7 @@ void AudioPlayer_TrackQueueDispatcher(const char *_itemToPlay, const uint32_t _l
857890 if (gPlayProperties .playMode != NO_PLAYLIST) {
858891 AudioPlayer_TrackControlToQueueSender (STOP);
859892 }
893+ free (filename);
860894 return ;
861895 }
862896
@@ -978,6 +1012,18 @@ void AudioPlayer_TrackQueueDispatcher(const char *_itemToPlay, const uint32_t _l
9781012 break ;
9791013 }
9801014
1015+ case TEXT_TO_SPEECH: { // This is also always just one "track"
1016+ Log_Println ((char *) FPSTR (modeWebstream), LOGLEVEL_NOTICE);
1017+ if (Wlan_IsConnected ()) {
1018+ xQueueSend (gTrackQueue , &(musicFiles), 0 );
1019+ } else {
1020+ Log_Println ((char *) FPSTR (webstreamNotAvailable), LOGLEVEL_ERROR);
1021+ System_IndicateError ();
1022+ gPlayProperties .playMode = NO_PLAYLIST;
1023+ }
1024+ break ;
1025+ }
1026+
9811027 case LOCAL_M3U: { // Can be one or multiple SD-files or webradio-stations; or a mix of both
9821028 Log_Println ((char *) FPSTR (modeWebstreamM3u), LOGLEVEL_NOTICE);
9831029 xQueueSend (gTrackQueue , &(musicFiles), 0 );
@@ -1053,6 +1099,18 @@ char **AudioPlayer_ReturnPlaylistFromWebstream(const char *_webUrl) {
10531099 return ++url;
10541100}
10551101
1102+ // Adds Text To Speech to playlist; same like SdCard_ReturnPlaylist() but always only one entry
1103+ char **AutioPlayer_ReturnPlaylistFromTextToSpeech (const char *_textToInsert) {
1104+ char *textToInsert = x_strdup (_textToInsert);
1105+ static char **playlist;
1106+ playlist = (char **)x_malloc (sizeof (char *) * 2 );
1107+ playlist[0 ] = x_strdup (" 1" ); // Number of files is always 1 in url-mode
1108+ playlist[1 ] = x_strdup (textToInsert);
1109+
1110+ free (textToInsert);
1111+ return ++playlist;
1112+ }
1113+
10561114// Adds new control-command to control-queue
10571115void AudioPlayer_TrackControlToQueueSender (const uint8_t trackCommand) {
10581116 xQueueSend (gTrackControlQueue , &trackCommand, 0 );
0 commit comments