SVXLINK: Local.tcl et ses améliorations

local_tclVoila pourquoi LOLA parle si bien…

Les nouvelles fonctionnalités sur F1ZBV ne pourraient pas fonctionner sans la modification de ce fichier c’est pour cela que j’ai décidé de vous le fournir et de vous le décrire.
Le principe des fonctions et de limiter les lignes de code et de pouvoir les appeler autant de fois que l’on en a besoin.
Le fichier Locale.tcl se place dans le repertoire de la langue pour nous: fr_FR
/usr/share/svxlink/sounds/fr_FR/events.d/Locale.tcl

Je pense que la majorité des nouvelles fonctions peuvent être compatibles avec d’autres langues, ou nécessitent quelques petites modifications.

Voici les fonctions que j’y ai ajoutées:
playTemp                                 dire la température
playFourDigitNumber       dire un chiffre à 4 décimales
playMonth                               dire le mois
playWindDir                          dire la direction d’après la lettre  (ex: N pour Nord)
playVoltage                             dire une tension

le fonctionnement est simple et commun à toute les fonctions. Il est nécessaire d’ajouter les fichiers sons correspondants.

A n’importe quelle moment dans votre programme tcl il vous suffira d’insérer cette fonction pour l’utiliser de la manière suivante:

<fonction> <variable> <;>
ex:
playNumber $resultat1;

playTemp
c'est fonction dira pour une valeur de 16.5: Seize degrés cinq                            playFourDigitNumber
c'est fonction dira pour une valeur de 1250: Mille deux cent cinquante
playMonth
c'est fonction dira pour une valeur de 02: Février 
playWindDir
c'est fonction dira pour une valeur de E: Est     

playVoltage
c'est fonction dira pour une valeur de 13.8Treize volts huit

Les codes complets du Locale.tcl ci-dessous:

###############################################################################
#
# Locale specific functions for playing back time, numbers and spelling words.
# Often, the functions in this file are the only ones that have to be
# reimplemented for a new language pack.
#
###############################################################################

#
#  25/06/2011   F1SMF    modif  for fr_FR
#  04/04/2016  F8ASB Add playTemp read temperature datas for fr_FR
#  01/10/2016  F8ASB Add functions:
#  playFourDigitNumber  Say number with four digits
#  playMonth            Say the month with the number
#  playWindDirAngle     Say winf direction with angle
#  playWindDir          Say wind direction with letter direction 
#  playTemp             Say temperature 
#  playVoltage          Say Voltage

#
# Spell the specified word using a phonetic alphabet
#
proc spellWord {word} {
  set word [string tolower $word];
  for {set i 0} {$i &lt; [string length $word]} {set i [expr $i + 1]} {
    set char [string index $word $i];
    if {$char == "*"} {
      playMsg "Default" "star";
    } elseif {$char == "/"} {
      playMsg "Default" "slash";
    } elseif {$char == "-"} {
      playMsg "Default" "dash";
    } elseif {[regexp {[a-z0-9]} $char]} {
      playMsg "Default" "phonetic_$char";
    }
  }
}

 
#
# Spell the specified number digit for digit
#
proc spellNumber {number} {
  for {set i 0} {$i &lt; [string length $number]} {set i [expr $i + 1]} {
    set ch [string index $number $i];
    if {$ch == "."} {
      playMsg "Default" "decimal";
    } else {
      playMsg "Default" "$ch";
    }
  }
}

 
#
# Say the specified two digit number (00 - 99)
#
proc playTwoDigitNumber {number} {
  if {[string length $number] != 2} {
    puts "*** WARNING: Function playTwoDigitNumber received a non two digit number: $number";
    return;
  }
 
  set first [string index $number 0];
if {($first == "0") || ($first == "O")} {
    playMsg "Default" $first;
    playMsg "Default" [string index $number 1];
   }  elseif {$first == "1"} {
        playMsg "Default" $number;
        }  elseif {$first == "7"} {
             playMsg "Default" "6X";
             if {[string index $number 1] == "1"} {
                 playMsg "Default" "and";
             }
             playMsg "Default" [expr $number - 60];
             } elseif {$first == "9"}  {
                  playMsg "Default" "8X";
                  playMsg "Default" [expr $number - 80];
                  } else {
                    playMsg "Default" "[string index $number 0]X";
                    if {[string index $number 1] == "1"} {
                        playMsg "Default" "and";
                    }
                    if {[string index $number 1] != "0"} {
                         playMsg "Default" "[string index $number 1]";
                    }
                  }
             }
#
# Say the specified three digit number (000 - 999)
#
proc playThreeDigitNumber {number} {
  if {[string length $number] != 3} {
    puts "*** WARNING: Function playThreeDigitNumber received a non three digit number: $number";
    return;
  }
 
  set first [string index $number 0];
    if {($first == "0") || ($first == "O")} {
    spellNumber $number
  } else {
    append first "00";
    playMsg "Default" $first;
    if {[string index $number 1] != "0"} {
      playTwoDigitNumber [string range $number 1 2];
    } elseif {[string index $number 2] != "0"} {
      playMsg "Default" [string index $number 2];
    }
  }
}

#
# Say the specified three digit number (1000 - 9999)
#
proc playFourDigitNumber {number} {
  if {[string length $number] != 6} {
    puts "*** WARNING: Function playFourDigitNumber received a non four digit number: $number";
    return;
  }
 
  set first [string index $number 0];
    if {($first == "1")} {
    playMsg "Default" "1000";
  } elseif {($first == "2")} {
    playMsg "Default" "2000";
  } elseif {($first == "3")} {
    playMsg "Default" "3000";
  } elseif {($first == "4")} {
    playMsg "Default" "4000";
  } elseif {($first == "5")} {
    playMsg "Default" "5000";
  } elseif {($first == "6")} {
    playMsg "Default" "6000";
  } elseif {($first == "7")} {
    playMsg "Default" "7000";
  } elseif {($first == "8")} {
    playMsg "Default" "8000";
  } elseif {($first == "9")} {
    playMsg "Default" "9000";  
  }
  set first [string index $number 1];
    if {($first == "0") || ($first == "O")} {
    playNumber [string range $number 2 5];
    } else {
    playNumber [string range $number 1 5];
    }
 }
#
#Say Month as intelligent as posible.
#
 
proc playMonth {Month} {
if { $Month =="01"} {
        playMsg "Months" "january";
    } elseif {$Month =="02"} {
        playMsg "Months" "February";
    } elseif {$Month =="03" } {
        playMsg "Months" "March";
    } elseif {$Month =="04" } {
        playMsg "Months" "April";
    } elseif {$Month =="05" } {
        playMsg "Months" "May";
    } elseif {$Month =="06" } {
        playMsg "Months" "June";
    } elseif {$Month =="07" } {
        playMsg "Months" "July";
    } elseif {$Month =="08" } {
        playMsg "Months" "August";
    } elseif {$Month =="09" } {
        playMsg "Months" "September";
    } elseif {$Month =="10" } {
        playMsg "Months" "October";
    } elseif {$Month =="11" } {
        playMsg "Months" "November";
    } elseif {$Month =="12" } {
        playMsg "Months" "December";  
}
 
}

#
#Say Wind Direction as intelligent as posible.
#
 
proc playWindDirAngle {windDir} {
 
if { $windDir =="N"} {
        puts "  Direction N"
        playMsg "WeatherStation" "North";
    } elseif {$windDir =="NNE"} {
        puts "  Direction NNE"
        playMsg "WeatherStation" "North";
        playMsg "WeatherStation" "North-East";
    } elseif {$windDir =="NE" } {
        puts "  Direction NE"
        playMsg "WeatherStation" "North-East";
    } elseif {$windDir =="ENE" } {
        puts "  Direction ENE"
        playMsg "WeatherStation" "East";
        playMsg "WeatherStation" "North-East";
    } elseif {$windDir =="E" } {
        puts "  Direction E"
        playMsg "WeatherStation" "East";
    } elseif {$windDir =="ESE"} {
        puts "  Direction ESE"
        playMsg "WeatherStation" "East";
         playMsg "WeatherStation" "South-East"; 
    } elseif {$windDir =="SE" } {
        puts "  Direction SE"
        playMsg "WeatherStation" "South-East";
    } elseif {$windDir =="SSE" } {
        puts "  Direction SSE"
        playMsg "WeatherStation" "South";
        playMsg "WeatherStation" "South-East";
    } elseif {$windDir =="S"} {
        puts "  Direction S"
        playMsg "WeatherStation" "South";
    } elseif {$windDir =="SSW" } {
        puts "  Direction SSW"
        playMsg "WeatherStation" "South";
        playMsg "WeatherStation" "South-West";
    } elseif {$windDir =="SW"} {
        puts "  Direction SW"
        playMsg "WeatherStation" "South-West";
    } elseif {$windDir =="WSW" } {
        puts "  Direction WSW"
        playMsg "WeatherStation" "West";
        playMsg "WeatherStation" "South-West";
    } elseif {$windDir =="W"} {
        puts "  Direction W"
        playMsg "WeatherStation" "West";
    } elseif {$windDir =="WNW"} {
        puts "  Direction WNW"
        playMsg "WeatherStation" "West";
        playMsg "WeatherStation" "North-West";
    } elseif {$windDir =="NW"} {
        puts "  Direction NW"
       playMsg "WeatherStation" "North-West";
    } elseif {$windDir =="NNW" } {
        puts "  Direction NNW"
       playMsg "WeatherStation" "North";
       playMsg "WeatherStation" "North-West";
    } else {
        puts "  Non disponible"
    }
    }
#
#Say Wind Direction with angle as intelligent as possible.
#
 
proc playWindDir {windDir} {
 
if { 0 &lt; $windDir &amp;&amp; $windDir &lt; 22.5} { puts " Direction N" playMsg "WeatherStation" "North"; } elseif {$windDir &gt;= 22.5 &amp;&amp; $windDir &lt; 45 } { puts " Direction N NE" playMsg "WeatherStation" "North"; playMsg "WeatherStation" "North-East"; } elseif {$windDir &gt;= 45 &amp;&amp; $windDir &lt; 67.5 } { puts " Direction NE" playMsg "WeatherStation" "North-East"; } elseif {$windDir &gt;= 67.5 &amp;&amp; $windDir &lt; 90 } { puts " Direction NE E" playMsg "WeatherStation" "North-East"; playMsg "WeatherStation" "East"; } elseif {$windDir &gt;= 90 &amp;&amp; $windDir &lt; 112.5 } { puts " Direction E" playMsg "WeatherStation" "East"; } elseif {$windDir &gt;= 112.5 &amp;&amp; $windDir &lt; 135 } { puts " Direction E SE" playMsg "WeatherStation" "East"; } elseif {$windDir &gt;= 135 &amp;&amp; $windDir &lt; 157.5 } { puts " Direction SE" playMsg "WeatherStation" "South-East"; } elseif {$windDir &gt;= 157.5 &amp;&amp; $windDir &lt; 180 } { puts " Direction SE S" playMsg "WeatherStation" "South-East"; playMsg "WeatherStation" "South"; } elseif {$windDir &gt;= 180 &amp;&amp; $windDir &lt; 202.5} { puts " Direction S" playMsg "WeatherStation" "South"; } elseif {$windDir &gt;= 202.5 &amp;&amp; $windDir &lt; 225 } { puts " Direction S SW" playMsg "WeatherStation" "South"; playMsg "WeatherStation" "South-West"; } elseif {$windDir &gt;= 225 &amp;&amp; $windDir &lt; 247.5} { puts " Direction SW" playMsg "WeatherStation" "South-West"; } elseif {$windDir &gt;= 247.5 &amp;&amp; $windDir &lt; 270 } { puts " Direction SW W" playMsg "WeatherStation" "South-West"; playMsg "WeatherStation" "West"; } elseif {$windDir &gt;= 270 &amp;&amp; $windDir &lt; 292.5} { puts " Direction W" playMsg "WeatherStation" "West"; } elseif {$windDir &gt;= 292.5 &amp;&amp; $windDir &lt; 315 } { puts " Direction W NW" playMsg "WeatherStation" "West"; playMsg "WeatherStation" "North-West"; } elseif {$windDir &gt;= 315 &amp;&amp; $windDir &lt; 337.5} { puts " Direction NW" playMsg "WeatherStation" "North-West"; } elseif {$windDir &gt;= 337.5 &amp;&amp; $windDir &lt; 359 } { puts " Direction NW N" playMsg "WeatherStation" "North-West"; playMsg "WeatherStation" "North"; } else { puts " Non disponible" } } # # Say a number as intelligent as possible. Examples: # # 1 - one # 24 - twentyfour # 245 - twohundred and fourtyfive # 1234 - twelve thirtyfour # 12345 - onehundred and twentythree fourtyfive # 136.5 - onehundred and thirtysix point five # proc playNumber {number} { if {[regexp {(\d+)\.(\d+)?} $number -&gt; integer fraction]} {
    playNumber $integer;
 
 
# No say 0 if decimal = 0
if {$fraction != 0} {
    playMsg "Default" "decimal";
    spellNumber $fraction;
}
 
    return;
  }
 
  while {[string length $number] &gt; 0} {
    set len [string length $number];
    if {$len == 1} {
      playMsg "Default" $number;
      set number "";
    } elseif {$len % 2 == 0} {
      playTwoDigitNumber [string range $number 0 1];
      set number [string range $number 2 end];
    } else {
      playThreeDigitNumber [string range $number 0 2];
      set number [string range $number 3 end];
    }
  }
}

#
# Say temperature as intelligent as possible. Examples:
#
 
proc playTemp {number} {
  if {[regexp {(\d+)\.(\d+)?} $number -&gt; integer fraction]} {
    playNumber $integer;
    playMsg "WeatherStation" "degree";
 
# No say 0 if decimal = 0
if {$fraction != 0} {
    spellNumber $fraction;
}
   return;
}
 
  while {[string length $number] &gt; 0} {
    set len [string length $number];
    if {$len == 1} {
      playMsg "Default" $number;
      set number "";
    } elseif {$len % 2 == 0} {
      playTwoDigitNumber [string range $number 0 1];
      set number [string range $number 2 end];
    } else {
      playThreeDigitNumber [string range $number 0 2];
      set number [string range $number 3 end];
    }
  }
}

#
# Say Voltage as intelligent as possible. Examples:
#
 
proc playVoltage {number} {
if {[regexp {(\d+)\.(\d+)?} $number -&gt; integer fraction]} {
    playNumber $integer;
    playMsg "Default" "volts";
 
# No say 0 if decimal = 0
if {$fraction != 0} {
    spellNumber $fraction;
}
   return;
}
 
  while {[string length $number] &gt; 0} {
    set len [string length $number];
    if {$len == 1} {
      playMsg "Default" $number;
      set number "";
    } elseif {$len % 2 == 0} {
      playTwoDigitNumber [string range $number 0 1];
      set number [string range $number 2 end];
    } else {
      playThreeDigitNumber [string range $number 0 2];
      set number [string range $number 3 end];
    }
  }
}

 
#
# Say the time specified by function arguments "hour" and "minute".
#
 
proc playTime {hour minute} {
# Strip white space and leading zeros. Check ranges.
  if {[scan $hour "%d" hour] != 1 || $hour &lt; 0 || $hour &gt; 23} {
    error "playTime: Non digit hour or value out of range: $hour"
  }
  if {[scan $minute "%d" minute] != 1 || $minute &lt; 0 || $minute &gt; 59} {
    error "playTime: Non digit minute or value out of range: $hour"
  }
  if {[string length $hour] == 1} {
     playMsg "Default" [expr $hour];
   } else {
     playTwoDigitNumber $hour;
    }
#  playSilence 250
  playMsg "Core" "time";
 
   if {$minute == 0} {
     return;
   }
    if {[string length $minute] == 1} {
        playMsg "Default" [expr $minute];
    } else {
        playTwoDigitNumber  $minute;
    }
}

#
# This file has not been truncated
#

Vous pouvez vous aussi créer vos propres fonctions et partager.

Vous pouvez recevoir un email dès la parution d’un article sur le Blog F8ASB.COM, entrez votre mail sur la fenêtre à droite et cliquer sur abonnement. Tous les articles en 1 clic ICI
Ce contenu a été publié dans Relais F1ZBU /F1ZBV, Svxlink, avec comme mot(s)-clé(s) , , , , , , , , , , , , , . Vous pouvez le mettre en favoris avec ce permalien.

Laisser un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Time limit is exhausted. Please reload CAPTCHA.