File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -61,9 +61,7 @@ from smallest import Smallest
6161
6262def main ():
6363 client = Smallest(api_key = os.environ.get(" SMALLEST_API_KEY" ))
64- audio_data = client.synthesize(" Hello, this is a test for sync synthesis function." )
65- with open (" sync_synthesize.wav" , " wb" ) as f:
66- f.write(audio_data)
64+ client.synthesize(" Hello, this is a test for sync synthesis function." , save_as = " sync_synthesize.wav" )
6765
6866if __name__ == " __main__" :
6967 main()
@@ -80,7 +78,7 @@ if __name__ == "__main__":
8078- ` remove_extra_silence ` : Remove additional silence (default: True)
8179
8280### Async
83- A synchronous text-to-speech synthesis client.
81+ Asynchronous text-to-speech synthesis client.
8482
8583** Basic Usage:**
8684``` python
@@ -93,9 +91,9 @@ client = AsyncSmallest(api_key=os.environ.get("SMALLEST_API_KEY"))
9391
9492async def main ():
9593 async with client as tts:
96- audio_bytes = await tts.synthesize(" Hello, this is a test of the async synthesis function." )
94+ await tts.synthesize(" Hello, this is a test of the async synthesis function." )
9795 async with aiofiles.open(" async_synthesize.wav" , " wb" ) as f:
98- await f.write(audio_bytes)
96+ await f.write(audio_bytes) # alternatively you can use the `save_as` parameter.
9997
10098if __name__ == " __main__" :
10199 asyncio.run(main())
Original file line number Diff line number Diff line change 11import os
2+ import wave
23import copy
34import requests
45from typing import Optional , Union , List
@@ -128,7 +129,11 @@ def synthesize(
128129 with open (save_as , "wb" ) as wf :
129130 wf .write (audio_content )
130131 else :
131- raise TTSError ("WAV header is required for saving audio. Set 'add_wav_header=True' to add a WAV header." )
132+ with wave .open (save_as , "wb" ) as wf :
133+ wf .setnchannels (1 )
134+ wf .setsampwidth (2 )
135+ wf .setframerate (self .opts .sample_rate )
136+ wf .writeframes (audio_content )
132137 return None
133138
134139 return audio_content
You can’t perform that action at this time.
0 commit comments