Skip to content

Commit 45ae94d

Browse files
author
thegamerhat
committedApr 15, 2023
improved error audio handling
1 parent a701858 commit 45ae94d

File tree

5 files changed

+27
-17
lines changed

5 files changed

+27
-17
lines changed
 

‎public/error_audio.mp3

22 KB
Binary file not shown.

‎src/HelloWorld/Title.tsx

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {interpolate, z} from 'remotion';
1+
import {interpolate, staticFile, z} from 'remotion';
22
import {useCallback, useEffect, useState} from 'react';
33
import {
44
Audio,
@@ -10,6 +10,7 @@ import {
1010
} from 'remotion';
1111
import {getTTSFromServer} from '../lib/client-utils';
1212
import {RequestMetadata} from '../lib/interfaces';
13+
import {FALLBACK_AUDIO_URL} from '../server/TextToSpeech/constants';
1314

1415
export const Text: React.FC<RequestMetadata> = (props) => {
1516
const {titleText, titleColor, pitch, speakingRate, voice, subtitleText} =
@@ -58,7 +59,15 @@ export const Text: React.FC<RequestMetadata> = (props) => {
5859
return (
5960
<>
6061
{audioUrl ? (
61-
<Audio id="TTS Audio" about="TTS Audio" src={audioUrl} />
62+
<Audio
63+
id="TTS Audio"
64+
about="TTS Audio"
65+
src={
66+
audioUrl === FALLBACK_AUDIO_URL
67+
? staticFile(FALLBACK_AUDIO_URL)
68+
: audioUrl
69+
}
70+
/>
6271
) : (
6372
<></>
6473
)}

‎src/Root.tsx

+11-11
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,17 @@ export const RemotionRoot: React.FC = () => {
4545
fps={30}
4646
width={1920}
4747
height={1080}
48-
defaultProps={{
49-
titleText:
50-
'Text to speech on Remotion using Google Text-to-Speech + Firebase' as const,
51-
subtitleText:
52-
'With these powerful tools, what will you build?' as const,
53-
titleColor: '#2E8AEA' as const,
54-
voice: 'Woman 1 (US)' as const,
55-
pitch: 0,
56-
speakingRate: 1,
57-
}}
58-
// As RequestMetadata
48+
defaultProps={
49+
{
50+
titleText:
51+
'Text to speech on Remotion using Google Text-to-Speech + Firebase',
52+
subtitleText: 'With these powerful tools, what will you build?',
53+
titleColor: '#2E8AEA',
54+
voice: 'Woman 1 (US)',
55+
pitch: 0,
56+
speakingRate: 1,
57+
} as const
58+
}
5959
/>
6060
</>
6161
);

‎src/server/TextToSpeech/constants.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import {staticFile} from 'remotion';
2-
31
export const FIREBASE_BUCKET_NAME = process.env.FIREBASE_BUCKET_NAME || '';
42

53
export const SERVER_URL = `http://localhost:${process.env.SERVER_PORT || 5050}`;
64
export const audioDirectoryInBucket = 'remotion-gtts';
75

8-
export const FALLBACK_AUDIO_URL = staticFile('error_audio.mp3');
6+
export const FALLBACK_AUDIO_URL = '/error_audio.mp3';
97

108
export const voices = {
119
'Man 1 (US)': {name: 'en-US-Neural2-D', languageCode: 'en-US'},

‎src/server/index.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ app.post(`/getdata`, async (req, res) => {
2727
return res.json({url: audioURL} as ServerResponse).end();
2828
} catch (err) {
2929
console.error(err);
30-
return res.json({url: FALLBACK_AUDIO_URL} as ServerResponse).end();
30+
return res
31+
.status(200)
32+
.json({url: FALLBACK_AUDIO_URL} as ServerResponse)
33+
.end();
3134
}
3235
});
3336

0 commit comments

Comments
 (0)
Please sign in to comment.