Is it possible to stream text-to-speech results directly to Azure Blob Storage?

Steffen Schreiber 25 Reputation points
2023-04-28T23:10:47.9766667+00:00

Hello,

I am building an app in node.js and I would like to stream the results from a call to the text-to-speech service directly to an Azure Blob Storage without first streaming the data to the server on which the app is running. Is this possible?

Currently, I am using speakSsmlAsync to retrieve audio and viseme data on the server the app is running on, but I want to reduce the amount of data going through this server by passing the audio and viseme data directly to an Azure Blob Storage.

Can this be done from an app hosted on a third-party server? Would it be easier (or possible at all) to do this from an app hosted on Azure App Service?

Thanks for any hints!

Best regards,
Steffen

Azure AI Speech
Azure AI Speech
An Azure service that integrates speech processing into apps and services.
1,713 questions
Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
2,843 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. YutongTie-MSFT 51,696 Reputation points
    2023-04-29T00:41:51.5833333+00:00

    Hello @Steffen Schreiber

    Thanks for reaching out to us, based on my personal experience, you may want to try createWriteStreamToBlockBlob method.

    Reference - [http://azure.github.io/azure-storage-node/BlobService.html#createWriteStreamToBlockBlob__anchor]

    It is possible to stream text-to-speech results directly to Azure Blob Storage without first streaming the data to the server on which the app is running. You can do this by using the createWriteStreamToBlockBlob method provided by the azure-storage package for Node.js.

    A quick sample you may want to refer to, please adjust it according to your scenario -

    const azure = require('azure-storage');
    const textToSpeech = require('your-text-to-speech-module');
    
    // Create a reference to the Azure Blob Storage container
    const containerName = 'your-container-name';
    const blobService = azure.createBlobService('your-storage-account', 'your-storage-access-key');
    const containerUrl = blobService.getUrl(containerName);
    
    // Generate text-to-speech audio and stream it directly to a blob
    const text = 'Hello, world!';
    const stream = textToSpeech.synthesize(text, { format: 'audio/wav' });
    const blobName = 'your-blob-name.wav';
    const blobStream = blobService.createWriteStreamToBlockBlob(containerName, blobName, (err, result) => {
      if (err) {
        console.error(err);
      } else {
        console.log(`Blob ${blobName} saved to ${containerUrl}`);
      }
    });
    
    stream.pipe(blobStream);
    
    

    This code generates text-to-speech audio for the text "Hello, world!" and streams it directly to a blob named "your-blob-name.wav" in an Azure Blob Storage container named "your-container-name". The createWriteStreamToBlockBlob method creates a writable stream that writes data to a block blob in the specified container. The pipe method is used to pipe the text-to-speech audio stream to the blob stream.

    You can use this code in an app hosted on a third-party server or on Azure App Service. However, you will need to ensure that your app has the necessary permissions to access your Azure Blob Storage account.

    Please let me know if you have any questions, we are happy to help further.

    Regards,

    Yutong

    -Please kindly accept the answer and vote 'Yes' if you feel helpful to support the community, thanks a lot.

    0 comments No comments

  2. Steffen Schreiber 25 Reputation points
    2023-04-29T17:35:50.4266667+00:00

    Hello @YutongTie-MSFT

    thanks, this looks promising! As visemes are essential for me, I need to use the speakSsmlAsync function from microsoft-cognitiveservices-speech-sdk , which accepts a stream argument of type AudioOutputStream, PushAudioOutputStreamCallback or fs.PathLike. Could I use an AudioOutputStream to stream the data to the blob storage? How can I make an AudioOutputStream compatible with a BlockBlobClient from the @azure/storage-blob npm package?

    Regarding the azure-storage package for npm: This seems to be deprecated and the advice is to use @azure/storage-blob instead. I assume I need to create a BlockBlobClient from that library in order to achieve my goal, right?

    Best regards,
    Steffen

    0 comments No comments

  3. Steffen Schreiber 25 Reputation points
    2023-04-29T17:44:24.44+00:00

    Sorry, this was a double post, but I don't seem to be able to delete this.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.