📜 ⬆️ ⬇️

Voice informer via Skype for 1C: Enterprise

Processing for 1C in the article allows you to receive an audio file with a speech generated by a computer based on a text line, call the other person via Skype and say it. The functionality is based on the .Net framework and API for Skype. The development will be useful not only for serious business applications, but also for home experiences and jokes to friends. For calls to real numbers, you need a refilled balance on Skype.

Presetting


If the Russian voice is not provided in the system, then it must be installed. By default, Windows 7 can only read English texts. For the Russification of voice, you need to install an additional Russian voice. Only the voice of ScanSoft Katerina Full 22kHz was found on the Internet (the legal possibility of using this voice is not completely understood). Many may find the voice slow. To speed it up, you need to make an entry in the registry:
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\ScanSoftKaterina_Full_22kHz] "pp type"="email" 

Skype allows you to interact with yourself through the skype4COM library .
You need to download this library and register it in the registry via regsvr32 skype4COM.dll . This operation may require administrator privileges.
After trying to use Skype for the first time, a query will appear in Skype. You need to give permission to the program 1cv8c.exe to use Skype. You can control the programs that have access through Settings-Advanced-Advanced Settings-Control other programs' access to Skype.
To access the .Net framework from 1C, you must install .Net Bridge. Now the latest version is 4.0.4.

C # Code Description


The SkypeSpeech class code is divided into 2 parts: sound generation through the SpeechSynthesizer class and working with Skype via SKYPE4COMLib.

Sound generation:
 SpeechSynthesizer reader = new SpeechSynthesizer(); if (!String.IsNullOrEmpty(voiceName)) {    var voice = reader.GetInstalledVoices().Where(m => m.VoiceInfo.Name == voiceName).FirstOrDefault();    if (voice != null)        reader.SelectVoice(voiceName); } reader.SetOutputToWaveFile(tempFilePath, new SpeechAudioFormatInfo(    16000,    AudioBitsPerSample.Sixteen,    AudioChannel.Mono )); reader.Speak(text); reader.SetOutputToNull(); reader.Dispose(); 

The features of the code are as follows. At the entrance to Skype you need to submit a wav-file with certain parameters, so the parameters are set explicitly. GetInstalledVoices and SelectVoice methods are used to control SpeechSynthesizer voices.
')
Work with Skype is carried out through Skype4COM. There are many examples on the Web, for example: http://habrahabr.ru/post/139319/ . All the examples that I looked at differ, in my opinion, with a complicated structure: the logic does not fit into one method, but is distributed between different methods and events. I wanted to fit all the logic in one procedure for clarity.

Connect to Skype. The second parameter in skype.Attach is replaced by true. This means that Skype will return control when the connection occurs.
 Skype skype = new Skype(); if (!skype.Client.IsRunning)    skype.Client.Start(true, true); skype.Attach(8, true); 

Call via Skype:
 Call call = skype.PlaceCall(target); do {     if (call.Status == TCallStatus.clsBusy        || call.Status == TCallStatus.clsCancelled        || call.Status == TCallStatus.clsFailed)        break;    System.Threading.Thread.Sleep(1); } while (call.Status != TCallStatus.clsInProgress); if (call.Status != TCallStatus.clsInProgress)    return; 

Playing a sound file. An attempt was made to determine the time of sounding by the time when the file is busy and not available for recording.
 call.set_InputDevice(TCallIoDeviceType.callIoDeviceTypeFile, waveFilePath); do {    System.Threading.Thread.Sleep(1000); } while (IsBusy(waveFilePath)); 

The IsBusy method looks like this:
 try {    using (FileStream stream = File.OpenWrite(filePath))    {        stream.Close();        return false;    } } catch (IOException) {    return true; } 

Description of 1C code


Initialization occurs in the event of the Opening Form form. Creating an object .Net Bridge.
 ("Elisy.NetBridge4"); AddIn = New("AddIn.ElisyNetBridge4"); net = AddIn.GetNet(); 

Load assembly from GAC:
 net.LoadAssembly("System.Speech, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); 

Loading the assembly from the layout for processing:
  = ("Elisy_SkypeSpeech_dll");  = Base64String(); assemblyBytes = net.CallStatic("System.Convert", "FromBase64String", ); net.CallStatic("System.Reflection.Assembly", "Load", assemblyBytes); 

For the generation of sound and sending a voice message via Skype, the Elisy.SkypeSpeech.SkypeSpeech class is responsible. Therefore, an object of this type must be created to access it.
 skypeSpeech = net.New("Elisy.SkypeSpeech.SkypeSpeech"); 

The command to generate an audio file skypeSpeech.CreateSpeech. The first parameter is the name of the file with the full path, the second parameter is the text of the message. The third parameter is the name of the voice.
 skypeSpeech.CreateSpeech(tempFilePath, ., "ScanSoft Katerina_Full_22kHz"); 

The command to send a Skype voice message skypeSpeech.SendAudioMessage. The first parameter is a phone number or Skype name. The second parameter is the name of the audio file.
 skypeSpeech.SendAudioMessage(., tempFilePath); 

Known problems and solutions


The recorded audio file pronounces only words written in Latin letters, for example, Skype. This means that the required Russian voice is not installed in the system or is not selected. It must be installed. If this voice is not ScanSoft Katerina Full 22kHz, then you need to correct the skypeSpeech.CreateSpeech call (PathFile, Object.Message, “ScanSoft Katerina_Full_22kHz”) to the desired voice name.

When you click "Call Skype TargetInvokationException with the message" Retrieving the class with the component {CLSID} {830690FC-BF2F-47A6-AC2D-330BCB402664} the class is not registered (Exception from HRESULT: 0x80040154 (REGDE_EE ). ". This means that the library for accessing Skype skype4COM.dll is not properly registered. It needs to be downloaded and registered with administrator rights through the regsvr32 skype4COM.dll.

What is not implemented


Processing works on the assumption that the transmission of a voice message will be carried out in the standard way: call - answer - message transfer - end of the call. In the current version of processing there is no status analysis: delivered or not delivered. For example, the phone at the subscriber may be busy or the subscriber began to listen to the message and independently interrupted the conversation.

In 1C, the temporary file could not be deleted at the end of processing. This is a strange phenomenon that could not be overcome, because in a test application through C # the temporary file was normally deleted.

Example of the received audio file for ScanSoft Katerina_Full_22kHz: audio.wav (180.78 kb)
Example of the received audio file for RHVoice Elena (Russian): audio-rhvoice.wav (159.42 kb)
Example of the received audio file for RHVoice Aleksandr (Russian): audio-rhvoice-alexandr.wav (196,76 kb)


Processing for 1C: Enterprise: SkypeSpeech.epf (14,21 kb)

Source: https://habr.com/ru/post/165883/


All Articles