1

I'm testing the Microsoft Azure Speech services, specifically trying to use Text-To-Speech. So, I'm using a free layer of Azure, and created a TimeTrigger Azure Function to read an e-mail, traverse through HTML and then call the Speech Service with the SDK Microsoft.CognitiveServices.Speech. I'm using the function.proj to load the nuget packages, loading S22.Imap and HtmlAgilityPack without any issues. But the speech package is triggering an exception: Unable to load DLL 'Microsoft.CognitiveServices.Speech.core.dll' or one of its dependencies: The specified module could not be found. (Exception from HRESULT: 0x8007007E). Am I able to use this package in an Azure Function? If so, what am I doing wrong?

I tried to remove the <PackageReference Include="Microsoft.CognitiveServices.Speech" Version="1.6.0" /> line from function.proj and deleted project.assets.json to reload the package but it didn't work.

This is my function.proj:

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <TargetFramework>netstandard2.0</TargetFramework>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="S22.Imap" Version="3.6.0" />
        <PackageReference Include="HtmlAgilityPack" Version="1.11.9" />
        <PackageReference Include="Microsoft.CognitiveServices.Speech" Version="1.6.0" />
    </ItemGroup>
</Project>

And this is my run.csx:

using System;
using S22.Imap;
using System.Net.Mail;
using HtmlAgilityPack;
using System.Threading.Tasks;
using Microsoft.CognitiveServices.Speech;
using System.Diagnostics;

public static void Run(TimerInfo myTimer, ILogger log)
{
    var username = "sample@gmail.com";
    var password = "sample";
    var subsKey = "sample";

    using(ImapClient client = new ImapClient("imap.gmail.com", 993, username, password, AuthMethod.Login, true))
    {
        IEnumerable<uint> uids = client.Search(SearchCondition.From("sample@sample.com"));
        IEnumerable<MailMessage> messages = client.GetMessages(uids);
        log.LogInformation($"Count: {messages.Count()}.");

        var msg = messages.FirstOrDefault();
        if(msg != null)
        {
            var doc = new HtmlDocument();
            doc.LoadHtml(msg.Body);

            var paragraphs = doc.DocumentNode.Descendants()
                .Where(x => x.Name == "p" && !string.IsNullOrEmpty(x.InnerText.Trim()))
                .ToList();

            var mailText = string.Empty;
            foreach(var par in paragraphs)
                mailText += par.InnerText;

            if(!string.IsNullOrEmpty(mailText))
            {
                var config = SpeechConfig.FromSubscription(subsKey, "myregion");
                config.SetSpeechSynthesisOutputFormat(SpeechSynthesisOutputFormat.Audio24Khz160KBitRateMonoMp3);
                config.SpeechSynthesisLanguage = "pt-BR";

                using (var synthesizer = new SpeechSynthesizer(config))
                {
                    using (var result = synthesizer.SpeakTextAsync(mailText).Result)
                    {
                        if (result.Reason == ResultReason.SynthesizingAudioCompleted)
                        {
                            //Do something with it
                        }
                        else if (result.Reason == ResultReason.Canceled)
                        {
                            var cancellation = SpeechSynthesisCancellationDetails.FromResult(result);
                            log.LogError($"CANCELED: Reason={cancellation.Reason}");

                            if (cancellation.Reason == CancellationReason.Error)
                            {
                                log.LogError($"CANCELED: ErrorCode={cancellation.ErrorCode}");
                                log.LogError($"CANCELED: ErrorDetails=[{cancellation.ErrorDetails}]");
                            }
                        }
                    }
                }
            }
        }
    }
}
Cristian Porto
  • 74
  • 1
  • 11

2 Answers2

1

You could try to delete the function.proj then recreate one and add Microsoft.CognitiveServices.Speech at first.

Make sure the Microsoft.CognitiveServices.Speech.core.dll has been installed in win-x86 and win-x64. Please refer to this issue.

enter image description here

Joey Cai
  • 18,968
  • 1
  • 20
  • 30
  • Deleted `function.proj` and `project.assets.json`, recreated it (this time only with Cognitive Services) and it still is unable to load the DLL. Maybe I should delete the Function App and try to create it from the scratch again? – Cristian Porto Jul 12 '19 at 12:50
  • 1
    I deleted the entire function, created again, this time only the speech service, but the error keep showing up. I gave up and used the REST API, and now it works. – Cristian Porto Jul 16 '19 at 10:59
  • 1
    The rest api you use is this [one](https://learn.microsoft.com/en-us/azure/cognitive-services/speech-service/rest-text-to-speech)? – Joey Cai Jul 17 '19 at 01:41
0

Mark as perquisite

When you publish mark Visual c++ 14 Runtime Libraries as prerequisite

Surendra
  • 19
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 25 '21 at 06:03