Skip to content

Commit f86bebd

Browse files
committed
Update client.py
1 parent 287fd50 commit f86bebd

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

ttsfm/client.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ def _get_headers_for_format(self, requested_format: AudioFormat) -> Dict[str, st
114114
Get appropriate headers to get the desired format from openai.fm.
115115
116116
Based on testing, openai.fm returns:
117-
- MP3: When using simple/minimal headers
118-
- WAV: When using full Chrome security headers
117+
- MP3: When using no headers or very minimal headers
118+
- WAV: When using more complex headers with specific Accept values
119119
120120
Args:
121121
requested_format: The desired audio format
@@ -129,15 +129,18 @@ def _get_headers_for_format(self, requested_format: AudioFormat) -> Dict[str, st
129129
target_format = get_supported_format(requested_format)
130130

131131
if target_format == AudioFormat.MP3:
132-
# Use minimal headers to get MP3 response
132+
# Use minimal headers to reliably get MP3 response
133+
# Testing shows that no headers or very basic headers work best for MP3
133134
return {
134-
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36',
135-
'Accept': 'audio/*,*/*;q=0.9'
135+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
136136
}
137137
else:
138-
# Use full realistic headers to get WAV response
138+
# Use more complex headers to get WAV response
139139
# This works for WAV, OPUS, AAC, FLAC, PCM formats
140-
return get_realistic_headers()
140+
return {
141+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36',
142+
'Accept': 'audio/*,*/*;q=0.9'
143+
}
141144

142145
def generate_speech(
143146
self,

0 commit comments

Comments
 (0)