Skip to content

Commit 418d808

Browse files
authored
Merge pull request #56 from speechmatics/fix/add-tts-workflow
Add TTS workflow
2 parents dd0453f + 66a4059 commit 418d808

File tree

3 files changed

+96
-15
lines changed

3 files changed

+96
-15
lines changed

.github/workflows/release-tts.yml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
name: Release TTS SDK
2+
3+
on:
4+
push:
5+
tags:
6+
- "tts/v*"
7+
8+
permissions:
9+
contents: read
10+
id-token: write
11+
12+
jobs:
13+
extract-version:
14+
runs-on: ubuntu-latest
15+
outputs:
16+
version: ${{ steps.extract.outputs.version }}
17+
steps:
18+
- name: Extract version from tag
19+
id: extract
20+
run: |
21+
# Extract version from tag (tts/v1.0.0 -> 1.0.0)
22+
VERSION=${GITHUB_REF#refs/tags/tts/v}
23+
echo "version=$VERSION" >> $GITHUB_OUTPUT
24+
echo "Extracted version: $VERSION"
25+
26+
test-tts:
27+
runs-on: ubuntu-latest
28+
strategy:
29+
matrix:
30+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
31+
steps:
32+
- uses: actions/checkout@v4
33+
- uses: actions/setup-python@v5
34+
with:
35+
python-version: ${{ matrix.python-version }}
36+
- name: Test TTS SDK
37+
run: |
38+
make install-dev
39+
make lint-tts
40+
make test-tts
41+
42+
release-build:
43+
runs-on: ubuntu-latest
44+
needs: [extract-version, test-tts]
45+
outputs:
46+
version: ${{ needs.extract-version.outputs.version }}
47+
steps:
48+
- uses: actions/checkout@v4
49+
50+
- uses: actions/setup-python@v5
51+
with:
52+
python-version: "3.x"
53+
54+
- name: Update package version in sdk/tts/speechmatics/tts/__init__.py
55+
run: |
56+
VERSION="${{ needs.extract-version.outputs.version }}"
57+
sed -i "s/0\.0\.0/$VERSION/g" ./sdk/tts/speechmatics/tts/__init__.py
58+
echo "Updated version to: $VERSION"
59+
cat ./sdk/tts/speechmatics/tts/__init__.py | grep __version__
60+
61+
- name: Build TTS SDK
62+
run: |
63+
make install-dev
64+
make build-tts
65+
66+
- name: Upload dist
67+
uses: actions/upload-artifact@v4
68+
with:
69+
name: tts-release-dist
70+
path: sdk/tts/dist/
71+
72+
pypi-publish:
73+
runs-on: ubuntu-latest
74+
needs: [release-build]
75+
environment:
76+
name: pypi-tts
77+
url: https://pypi.org/project/speechmatics-tts/${{ needs.release-build.outputs.version }}
78+
79+
steps:
80+
- name: Retrieve release dist
81+
uses: actions/download-artifact@v4
82+
with:
83+
name: tts-release-dist
84+
path: dist/
85+
86+
- name: Publish to PyPI
87+
uses: pypa/gh-action-pypi-publish@release/v1
88+
with:
89+
packages-dir: dist/
90+
password: ${{ secrets.PYPI_ORG_TOKEN }}

sdk/tts/README.md

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,19 @@ pip install speechmatics-tts
2424
```python
2525
import asyncio
2626

27-
import wave
28-
from pathlib import Path
29-
3027
from speechmatics.tts import AsyncClient, Voice, OutputFormat
3128

32-
async def save_audio(audio_data: bytes, filename: str) -> None:
33-
with wave.open(filename, "wb") as wav:
34-
wav.setnchannels(1) # Mono
35-
wav.setsampwidth(2) # 16-bit
36-
wav.setframerate(16000) # 16kHz
37-
wav.writeframes(audio_data)
38-
3929
# Generate speech data from text and save to WAV file
4030
async def main():
4131
async with AsyncClient() as client:
4232
async with await client.generate(
43-
text="Welcome to the future of audio generation from text!",
33+
text="Welcome to the future of voice AI!",
4434
voice=Voice.SARAH,
45-
output_format=OutputFormat.RAW_PCM_16000
35+
output_format=OutputFormat.WAV_16000
4636
) as response:
4737
audio = b''.join([chunk async for chunk in response.content.iter_chunked(1024)])
48-
await save_audio(audio, "output.wav")
38+
with open("output.wav", "wb") as f:
39+
f.write(audio)
4940

5041

5142
# Run the async main function

sdk/tts/speechmatics/tts/_helpers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Utility functions for the Speechmatics Batch SDK.
2+
Utility functions for the Speechmatics TTS SDK.
33
"""
44

55
from __future__ import annotations
@@ -47,7 +47,7 @@ async def prepare_audio_file(
4747

4848
def get_version() -> str:
4949
try:
50-
return importlib.metadata.version("speechmatics-batch")
50+
return importlib.metadata.version("speechmatics-tts")
5151
except importlib.metadata.PackageNotFoundError:
5252
try:
5353
from . import __version__

0 commit comments

Comments
 (0)