                      }
                    } catch (jsonError) {
                        console.error('Failed to parse error response:', jsonError);
                    }
                    throw new Error(errorMessage);
                }

                const audioBlob = await response.blob();
                const url = URL.createObjectURL(audioBlob);
                audioPlayer.src = url;
                audioContainer.style.display = 'block';
            } catch (err) {
                console.error