Skip to content

Commit 1e03355

Browse files
committed
feat(mouthing): respond with ipa and swu
1 parent d2bbc55 commit 1e03355

File tree

4 files changed

+31
-14
lines changed

4 files changed

+31
-14
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ signwriting_to_image(fsw)
9494
![AS10011S10019S2e704S2e748M525x535S2e748483x510S10011501x466S20544510x500S10019476x475](signwriting/visualizer/test_assets/AS10011S10019S2e704S2e748M525x535S2e748483x510S10011501x466S20544510x500S10019476x475.png)
9595

9696
To use the visualizer with the server, you can hit:
97-
https://signwriting-sxie2r74ua-uc.a.run.app//visualizer?fsw=M525x535S2e748483x510S10011501x466S2e704510x500S10019476x475
97+
https://signwriting-sxie2r74ua-uc.a.run.app/visualizer?fsw=M525x535S2e748483x510S10011501x466S2e704510x500S10019476x475
9898

9999
### `signwriting.utils`
100100

@@ -127,7 +127,7 @@ spell(word, language)
127127
```
128128

129129
To use the fingerspelling with the server, you can hit:
130-
https://signwriting-sxie2r74ua-uc.a.run.app//fingerspelling?text=hello&signed_language=ase
130+
https://signwriting-sxie2r74ua-uc.a.run.app/fingerspelling?text=hello&signed_language=ase
131131

132132
### `signwriting.mouthing`
133133

@@ -146,7 +146,7 @@ Note: Installing English support for `epitran` requires extra steps,
146146
see "Install flite" at [mouthing/README.md](signwriting/mouthing/README.md).
147147

148148
To use the mouthing with the server, you can hit:
149-
https://signwriting-sxie2r74ua-uc.a.run.app//mouthing?text=hello&spoken_language=eng-Latn
149+
https://signwriting-sxie2r74ua-uc.a.run.app/mouthing?text=hello&spoken_language=eng-Latn
150150

151151

152152
## Cite

signwriting/mouthing/mouthing.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,27 @@
22
import functools
33
import json
44
import re
5+
from dataclasses import dataclass
56
from pathlib import Path
6-
from typing import Union
7+
from typing import Union, Optional
78

89
from epitran import Epitran
910

1011
from signwriting.formats.fsw_to_sign import fsw_to_sign
1112
from signwriting.formats.sign_to_fsw import sign_to_fsw
13+
from signwriting.formats.fsw_to_swu import fsw2swu
1214
from signwriting.utils.join_signs import join_signs_horizontal, sign_from_symbols
1315

1416
MOUTHING_INDEX = Path(__file__).parent / "mouthing.json"
1517

1618

19+
@dataclass
20+
class MouthingResult:
21+
ipa: str
22+
fsw: Optional[str]
23+
swu: Optional[str]
24+
25+
1726
@functools.lru_cache()
1827
def get_mouthings():
1928
with open(MOUTHING_INDEX, "r", encoding="utf-8") as f:
@@ -74,14 +83,17 @@ def mouth_ipa(characters: str, aspiration=False) -> Union[str, None]:
7483
return join_signs_horizontal(*words, spacing=10)
7584

7685

77-
def mouth(word: str, language: str, aspiration=False):
86+
def mouth(word: str, language: str, aspiration=False) -> MouthingResult:
7887
epi = Epitran(language, ligatures=True)
7988
ipa = epi.transliterate(word)
8089

8190
mouthing_fsw = mouth_ipa(ipa, aspiration=aspiration)
8291
if mouthing_fsw is None:
8392
print(f"Failed to mouth {word}, IPA: {ipa}")
84-
return mouthing_fsw
93+
94+
mouthing_swu = fsw2swu(mouthing_fsw) if mouthing_fsw else None
95+
96+
return MouthingResult(ipa=ipa, fsw=mouthing_fsw, swu=mouthing_swu)
8597

8698

8799
if __name__ == "__main__":

signwriting/mouthing/server.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,19 @@
44
from signwriting.mouthing.mouthing import mouth
55

66
parser = reqparse.RequestParser()
7-
parser.add_argument('text', type=str, required=True, help='Text to mouth')
8-
parser.add_argument('spoken_language', type=str, required=True,
7+
parser.add_argument('text', type=str, required=True, location='args', help='Text to mouth')
8+
parser.add_argument('spoken_language', type=str, required=True, location='args',
99
help='Spoken Language code. See "Language Support" at https://pypi.org/project/epitran/')
1010

1111

1212
class Mouthing(Resource):
1313
def get(self):
1414
args = parser.parse_args()
1515

16-
fsw = mouth(args["text"], language=args["spoken_language"])
17-
return make_response(jsonify({"fsw": fsw}), 200)
16+
result = mouth(args["text"], language=args["spoken_language"])
17+
18+
return make_response(jsonify({
19+
"ipa": result.ipa,
20+
"fsw": result.fsw,
21+
"swu": result.swu
22+
}), 200)

signwriting/visualizer/visualize.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,14 @@ def layout_signwriting(images: List[Image.Image], direction: str) -> Image.Image
8787
max_height = max(img.height for img in images)
8888
total_width = sum(img.width for img in images) + GAP * (len(images) - 1)
8989
size = (total_width, max_height)
90-
paste_position = lambda offset, img: (offset, (max_height - img.height) // 2)
91-
offset_increment = lambda img: img.width + GAP
90+
paste_position = lambda offset, img: (offset, (max_height - img.height) // 2) # noqa: E731
91+
offset_increment = lambda img: img.width + GAP # noqa: E731
9292
else:
9393
max_width = max(img.width for img in images)
9494
total_height = sum(img.height for img in images) + GAP * (len(images) - 1)
9595
size = (max_width, total_height)
96-
paste_position = lambda offset, img: ((max_width - img.width) // 2, offset)
97-
offset_increment = lambda img: img.height + GAP
96+
paste_position = lambda offset, img: ((max_width - img.width) // 2, offset) # noqa: E731
97+
offset_increment = lambda img: img.height + GAP # noqa: E731
9898

9999
layout_image = Image.new("RGBA", size, (255, 255, 255, 0))
100100
offset = 0

0 commit comments

Comments
 (0)