O
O
Otakukz172021-06-04 14:16:01
Java
Otakukz17, 2021-06-04 14:16:01

How to make a personalized voice greeting in Java?

There is a list of the most popular customer names. For each client, there is a unique greeting sound that the IVR must speak.

I have a task to write logic in Java so that by the name of the client, give out the name of the sound.
There are about 200 names, not counting variations of the same name.
The first thing that came to my mind was to use the condition:

if (name.equals("SERGEY") || name.equals("Сергей") || name.equals("Сергiй") ) 
{ 
SimplePrompt block=new SimplePrompt("SERGEY_name_xx.wav".replace("xx",language)); 
}


Since this option requires writing a large number of lines of code, I'm thinking about how to implement this task.
I ask for your help.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dmitry Roo, 2021-06-04
@xez

More or less like this:

var userPrompts = Map.of("SERGEY", new SimplePrompt("SERGEY.wav"),
                         "ANDREW", new SimplePrompt("ANDREW.wav"));

var block = userPrompts.get("SERGEY");

It would also be nice to add the filling of the map from the database here ...

O
Orkhan, 2021-06-04
Hasanly @azerphoenix

Good afternoon!

Since this option requires writing a large number of lines of code, I'm thinking about how to implement this task.

If I were you, I would consider using some suitable pattern.
using if ... else or switch case is certainly cool, but writing such a colossus for several thousand lines is somehow not very good.
You might consider applying patterns - Command, Strategy or Chain of Responsibility
You can start with these resources:
https://stackoverflow.com/questions/28049094/repla...
https://refactoring.guru/

P
pogoreli, 2021-06-04
@pogoreli

ienumerator
case switch

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question