Performing operations in between each subscription using RxJS

I have successfully created an angular pipe that converts text into spoken words.

Currently, I am working on implementing a feature where the user can view the sentence being spoken while the audio is playing, instead of after it has finished (which is how it currently works).

If I have an Observable containing strings, how can I immediately subscribe to each one, play the audio until completion, and then move on to the next string?

transform(input: Observable<string>, ...args) {
  if (input) {
    return input.concatMap(text => {

      if (!text)
        return Observable.empty()

      let promise = Promise.resolve()
      .then(() =>
        this.service.textToSpeech(text)
      )
      .then((audio) =>
        new Promise<string>((resolve) => {
          player.play(audio)
          player.addEventListener("ended", () => {
            resolve(text)  // The user sees the text when the audio stops..
          })
        })
      )

      return Observable.fromPromise(promise)

    })
  }
}

Answer №1

I managed to find a solution by incorporating an offset in my zipping technique, as shown below (where f(a) represents the audio corresponding to text a):

a, null
b, f(a)
c, f(b)
null, f(c)

Although the code may not be aesthetically pleasing, it gets the job done... On a positive note, the audio playback no longer interferes with the text-to-speech API requests.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What could be causing the checkbox filter to malfunction in VueJS?

After spending a solid 8 hours attempting to make this work, I'm still struggling. My main goal is to display a loop that shows all items by default. Then, when a user selects a checkbox, it will filter out the items where they are set to false. Here ...

Passing an ID in Next.js without showing it in the URL

I am looking to transfer the product id from the category page to the product page without showing it in the URL Category.js <h2> <Link href={{ pathname: `/product/car/${title}`, query: { id: Item.id, }, }} as={`/p ...

Using a local variable with jquery getJSON: A comprehensive guide

I am looking to expand the autocomplete capabilities of Ace Editor and I require a JSON file containing words. Here is my code snippet: function load_completions() { var object = $('#preview').attr('class'); $.ajax({ ...

Opening the identical document

In my coding scenario, I am programmatically writing to a text file using Java while simultaneously attempting to read from the same file using jQuery. Unfortunately, I am encountering an issue where jQuery is unable to detect the updated content whenever ...

Executing a function within JSX to dismiss a modal in NextJS

I am currently utilizing the Tanstack React Query library to perform a POST request from a Modal that includes a form: const addDay = (day: TDay) => { const apiURL = process.env.NEXT_PUBLIC_SERVER_URL const queryURL = apiURL + router ...

Issue with Vue Application: Footer is failing to render, resulting in 2 errors and a warning

Currently, I am in the process of revising and experimenting with VUE 3. I decided to create a Task Tracker application but ran into an issue when trying to add a footer. A few problems arose: It's important to note that I attempted to integrate Vue- ...

Script tag for Next.js reloading functionality

I have been facing a challenge while trying to integrate third-party commenting scripts like (disqus, remark42, hyvor) into my next.js application. The issue I encountered is that the script only loads on the initial page load. Subsequently, I need to refr ...

Adjusting the visibility leads to modification of the font size

My iPhone seems to be the only device affected by this issue. Every time I toggle the visibility of an element, it results in a different font size. The problem only arises when I show and hide multiple elements within the "Show All" section. <style& ...

Tips for optimizing data retrieval from a MongoDB collection by leveraging Node.js, Mongoose, and MongoDB connections efficiently

In my scenario, I have two key collections: orders and driverResponse. The driver has the ability to either accept or decline an order, with his response being saved in the driverResponse collection. When the driver revisits the order, it is important to ...

Encountering a MySQL Server error while attempting to insert exclusive records using the ROWCOUNT function

Currently, I am experimenting with some JavaScript code in Node.js, utilizing the MySQL package within Node and running MySQL queries in the Visual Studio Code terminal. Despite trying various approaches such as adding (), '', "", etc., isolatin ...

Retrieve the DOM variable before it undergoes changes upon clicking the redirect button

I have been struggling for a long time to figure out how to maintain variables between page refreshes and different pages within a single browser session opened using Selenium in Python. Unfortunately, I have tried storing variables in localStorage, sessio ...

Understanding the process of accessing data within the beforeRouteLeave component guard in Vue

Having trouble accessing data within beforeRouteLeave as everything appears to be undefined Check out the code snippet below: <template> ... </template> <style lang="scss"> ... </style> <script> export default { ...

Creating Stylish Checkboxes with Bootstrap

I'm attempting to customize a checkbox to have a specific appearance. example of desired checkbox design Here is what I have tried so far: <div class="col-2"> <label for="WitholdingTax">Charge</label> <div class="input-g ...

Fixed navbar does not collapse when clicking on items on a small-screen device

Currently, I am working with Bootstrap 4 and I was able to resolve a similar issue with Bootstrap 3. However, it seems that Bootstrap 4 is not behaving the same way. I am facing a roadblock and this is the final piece needed to complete the project. This ...

What is the process for utilizing JEST to test a REST API built with Express?

Is it possible to solely use JEST for testing my rest API endpoints in express? I've undertaken various articles and browsed through questions on Stack Overflow to explore how this can be achieved. However, it seems like most individuals prefer using ...

Verifying date changes using React/Redux and Moment.JS

I'm currently working on a React+Redux application where I use Moment.js to display the date. I need a function that will execute whenever the date changes. Right now, I have a function for checking the date: checkDate(local) { if (local === n ...

The attribute 'use' is not found within the data type 'typeof...', and the property 'extend' is not present within the data type 'typeof'

As I embark on building my very first Vue app using TypeScript, I find myself facing a frustrating issue: Property 'xxx' does not exist on type 'typeof. Despite my efforts to research similar problems, none of the suggested solutions have pr ...

Within the Django framework, where should I place the Python script that needs to be called by a JavaScript function?

When it comes to Django and file locations, I often find myself getting confused a lot, especially since I am using Django 1.10. Currently, in my static/(django-proj-name)/js/ folder, I have my main.js file where I need to call a Python script along with t ...

Inadequate grid data retrieval (This problem arises randomly)

During the process of loading data in a grid on our production server, I encountered a script error at the bottom left corner of the page. Interestingly, this error only occurs on the production server and works perfectly fine on the local server. Here ar ...

Is it possible to transfer the setState function between different contextProviders?

I'm encountering difficulties in setting a state when passing the context provider to other elements. Here is my code snippet. I have created a FancyboxContext so that I can easily access it from anywhere in the app. import React, { createContext, use ...