#How do I go from base64 string to wav file in Node.js
1 messages · Page 1 of 1 (latest)
AI-generated Answer for johnwilla
The information provided does not include a direct method to convert a base64 string to a wav file in Node.js. However, it does provide a Python example of how to convert a base64 string to a wav file. Here's the Python code for reference:
from scipy.io import wavfile
from pydub import AudioSegment
from io import BytesIO
def tts_out(text: str):
response = elevenlabs_client.text_to_speech.convert(
text=text,
voice_id="xxxxxxxxxxxxxxx",
optimize_streaming_latency="0",
output_format="mp3_22050_32",
)
audio_stream = BytesIO()
for chunk in response:
if chunk:
audio_stream.write(chunk)
audio_stream.seek(0)
audio = AudioSegment.from_mp3(audio_stream)
wav_io = BytesIO()
wav_file = audio.export(wav_io, format="wav")
wav_io.seek(0)
sample_rate, audio_data = wavfile.read(wav_io)
return (sample_rate, audio_data)
This Python code uses the scipy.io.wavfile and pydub.AudioSegment libraries to convert the audio stream to a wav file. You might be able to find similar libraries or methods in Node.js to achieve the same result.
I need this in typescript. The solution should handle streamed base64 data