Skip to content

Commit

Permalink
Merge pull request #574 from webitel/fix/text-to-speech
Browse files Browse the repository at this point in the history
Fix/text to speech [WTEL-4109]
  • Loading branch information
liza-pohranichna authored Dec 21, 2023
2 parents 1de1a88 + aacee31 commit addaaa5
Showing 1 changed file with 7 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ import applyTransform, {
camelToSnake,
generateUrl,
notify,
snakeToCamel,
} from '@webitel/ui-sdk/src/api/transformers';
import instance from '../../../../../../../app/api/instance';

const baseUrl = '/storage/tts/stream';
import instance from '../../../../../../../app/api/instance';

const getTtsStreamUrl = (params, apiUrl = false) => {
const baseUrl = '/storage/tts/stream';
let url = applyTransform(params, [
(params) => ({
...params,
Expand All @@ -17,21 +16,18 @@ const getTtsStreamUrl = (params, apiUrl = false) => {
camelToSnake(),
generateUrl(baseUrl),
]);

if (apiUrl) url = `${process.env.VITE_API_URL}${url}`;

if (apiUrl) url = `${import.meta.env.VITE_API_URL}${url}`;
return url;
};

const getTts = async (params) => {

const url = getTtsStreamUrl(params);
const url = getTtsStreamUrl(params, true);

try {
const response = await instance.get(url);
return applyTransform(response.data, [
snakeToCamel(),
]);
const response = await fetch(url);
if (!response.ok) throw new Error(response.status);
return response.blob();
} catch (err) {
throw applyTransform(err, [
notify(({ callback }) => callback({
Expand Down

0 comments on commit addaaa5

Please sign in to comment.