Home » International Civil Aviation Organization text to speech in python

International Civil Aviation Organization text to speech in python

Java SE 11 Developer (Upgrade) [1Z0-817]
Java SE 11 Programmer II [1Z0-816] Practice Tests
1 Year Subscription
Spring Framework Basics Video Course
Java SE 11 Programmer I [1Z0-815] Practice Tests
Oracle Java Certification

The International Civil Aviation Organization (ICAO) alphabet assigns code words to the letters of the English alphabet acrophonically (Alfa for A, Bravo for B, etc.) so that critical combinations of letters (and numbers) can be pronounced and understood by those who transmit and receive voice messages by radio or telephone regardless of their native language, especially when the safety of navigation or persons is essential.

Here is a Python dictionary covering one version of the ICAO alphabet:

d = {'a':'alfa', 'b':'bravo', 'c':'charlie', 'd':'delta', 'e':'echo',
'f':'foxtrot', 'g':'golf', 'h':'hotel', 'i':'india', 'j':'juliett',
'k':'kilo', 'l':'lima', 'm':'mike', 'n':'november', 'o':'oscar',
'p':'papa', 'q':'quebec', 'r':'romeo', 's':'sierra', 't':'tango',
'u':'uniform', 'v':'victor', 'w':'whiskey', 'x':'x-ray', 'y':'yankee',
'z':'zulu'}

Your task in this exercise is to write a procedure speak_ICAO() able to translate any text (i.e. any string) into spoken ICAO words.

You need to import at least two libraries: os and time.

On a mac, you have access to the system TTS (Text-To-Speech) as follows: os.system(‘say ‘ + msg), where msg is the string to be spoken. (Under UNIX/Linux and Windows, something similar might exist.)

Apart from the text to be spoken, your procedure also needs to accept two additional parameters: a float indicating the length of the pause between each spoken ICAO word, and a float indicating the length of the pause between each word spoken.

Examples

 

import os, re, time
icao_dict = {'a':'alfa', 'b':'bravo', 'c':'charlie', 'd':'delta', 'e':'echo',
    'f':'foxtrot', 'g':'golf', 'h':'hotel', 'i':'india', 'j':'juliett',
    'k':'kilo', 'l':'lima', 'm':'mike', 'n':'november', 'o':'oscar',
    'p':'papa', 'q':'quebec', 'r':'romeo', 's':'sierra', 't':'tango',
    'u':'uniform', 'v':'victor', 'w':'whiskey', 'x':'x-ray', 'y':'yankee',
    'z':'zulu'}

def speak_ICAO(message,icao_pause_length,word_pause_length):
    #removes all characters that aren't words
    message = re.sub(r'[^A-Za-z]', ' ', message)
    #splits it into individual words
    message = message.lower().split(' ')

    for word in message:
        for char in word:
            os.system(str(icao_dict[char]))
            time.sleep(icao_pause_length)
        time.sleep(word_pause_length)

speak_ICAO('Hello, my name is Aaron', 0.5, 1)

 

import os, time, re
#original_message = input("Enter a line: ")
message = "Hello Shovon"

d = {'a':'alfa', 'b':'bravo', 'c':'charlie', 'd':'delta', 'e':'echo', 'f':'foxtrot',
     'g':'golf', 'h':'hotel', 'i':'india', 'j':'juliett', 'k':'kilo', 'l':'lima',
     'm':'mike', 'n':'november', 'o':'oscar', 'p':'papa', 'q':'quebec', 'r':'romeo',
     's':'sierra', 't':'tango', 'u':'uniform', 'v':'victor', 'w':'whiskey', 
     'x':'x-ray', 'y':'yankee', 'z':'zulu'}

def icao(message, char_pause, word_pause):
    word_list = re.findall('\w+',message)
    for word in word_list:
        word = word.lower()
        for c in word:
            if c in d:
                icao_word = d[c]
                print(icao_word+char_pause,end="")
        print(word_pause,end="")            
icao(message," ","    ")

 

You may also like

Leave a Comment

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More