Skip to content

Commit 5bd204f

Browse files
authored
Merge pull request #7 from smallest-inc/fix
fix changes
2 parents 415ed66 + 705c882 commit 5bd204f

2 files changed

Lines changed: 10 additions & 7 deletions

File tree

README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@ from smallest import Smallest
6161

6262
def 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

6866
if __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

9492
async 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

10098
if __name__ == "__main__":
10199
asyncio.run(main())

smallest/tts.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import wave
23
import copy
34
import requests
45
from 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

0 commit comments

Comments
 (0)