Skip to content

Commit

Permalink
Migrated all speech synthesis and transcription over to using the new…
Browse files Browse the repository at this point in the history
… icespeak package
  • Loading branch information
sveinbjornt committed Sep 13, 2023
1 parent 7cf11b1 commit a87a4bd
Show file tree
Hide file tree
Showing 39 changed files with 110 additions and 4,174 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ in [`queries/examples`](queries/examples).

## Running Greynir

Once you have followed the installation and setup instructions above, change to the
Greynir repository and activate the virtual environment:
Once you have followed the installation and setup instructions above, change
to the Greynir repository and activate the virtual environment:

```bash
cd Greynir
Expand Down Expand Up @@ -265,7 +265,7 @@ GNU GPLv3 or other compatible licenses.

## Acknowledgements

Greynir uses the official BÍN ([Beygingarlýsing íslensks nútímamáls](https://bin.arnastofnun.is))
Greynir uses the BÍN ([Beygingarlýsing íslensks nútímamáls](https://bin.arnastofnun.is))
lexicon and database of Icelandic word forms to identify words and find their
potential meanings and lemmas. The database is included in
[BinPackage](https://github.com/mideind/BinPackage) in compressed form.
Expand Down
2 changes: 1 addition & 1 deletion queries/atm.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
AnswerTuple,
LatLonTuple,
)
from speech.trans.num import number_to_text
from icespeak.transcribe.num import number_to_text
from utility import QUERIES_RESOURCES_DIR

# TODO: fetch ATM data from a web service instead of a local file every once in a while
Expand Down
9 changes: 7 additions & 2 deletions queries/bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@
gen_answer,
read_grammar_file,
)
from speech.trans import gssml, strip_markup
from icespeak import gssml
from icespeak.transcribe import strip_markup
from settings import Settings
from geo import in_iceland

Expand Down Expand Up @@ -706,7 +707,11 @@ def assemble(x: Iterable[str]) -> str:
voice_answer = assemble(va)
return dict(answer=answer), answer, voice_answer

_ROUTE_SORT: Callable[[str], int] = lambda num: int("".join(i for i in num if i.isdecimal()))

_ROUTE_SORT: Callable[[str], int] = lambda num: int(
"".join(i for i in num if i.isdecimal())
)


def query_which_route(query: Query, result: Result):
"""Which routes stop at a given bus stop"""
Expand Down
11 changes: 8 additions & 3 deletions queries/flights.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
from queries.util import query_json_api, is_plural, read_grammar_file
from tree import Result, Node
from settings import changedlocale
from speech.trans import gssml
from icespeak import gssml

from reynir import NounPhrase
from geo import capitalize_placename, iceprep_for_placename, icelandic_city_name
Expand Down Expand Up @@ -140,6 +140,7 @@ def QFlightsDepLoc(node: Node, params: QueryStateDict, result: Result) -> None:
maxsize=2, ttl=_FLIGHTS_CACHE_TTL
)


# For type checking
class FlightType(TypedDict, total=False):
No: str
Expand Down Expand Up @@ -219,7 +220,9 @@ def _filter_flight_data(
"""
flight_time: datetime
flight: FlightType
now: datetime = datetime.now(timezone.utc) # Timezone aware datetime (don't change to datetime.utcnow()!)
now: datetime = datetime.now(
timezone.utc
) # Timezone aware datetime (don't change to datetime.utcnow()!)

matching_flights: FlightList = []
for flight in flights:
Expand Down Expand Up @@ -388,7 +391,9 @@ def _process_result(result: Result) -> Dict[str, str]:

from_date: datetime
to_date: datetime
now = datetime.now(timezone.utc) # Timezone aware datetime, don't change to .utcnow()!
now = datetime.now(
timezone.utc
) # Timezone aware datetime, don't change to .utcnow()!
days: int = result.get("day_count", 5) # Check 5 days into future by default
from_date = result.get("from_date", now)
to_date = result.get("to_date", now + timedelta(days=days))
Expand Down
4 changes: 2 additions & 2 deletions queries/gpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
from queries.currency import fetch_exchange_rates
from queries.userloc import locality_and_country
from settings import Settings
from speech.trans import gssml
from speech.trans.num import numbers_to_ordinal, years_to_text
from icespeak import gssml
from icespeak.transcribe.num import numbers_to_ordinal, years_to_text
from queries.util.openai_gpt import (
OPENAI_KEY_PRESENT,
jdump,
Expand Down
2 changes: 1 addition & 1 deletion queries/ja.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
from reynir.bindb import GreynirBin

from queries.util import query_json_api, gen_answer, read_grammar_file
from speech.trans import gssml
from icespeak import gssml

from queries import AnswerTuple, Query, QueryStateDict
from tree import Result, Node
Expand Down
2 changes: 1 addition & 1 deletion queries/news.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import cachetools # type: ignore
import random

from speech.trans import gssml
from icespeak import gssml
from queries import Query, QueryStateDict, AnswerTuple
from queries.util import gen_answer, query_json_api, read_grammar_file
from tree import Result, Node
Expand Down
2 changes: 1 addition & 1 deletion queries/petrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
LatLonTuple,
read_grammar_file,
)
from speech.trans import gssml
from icespeak import gssml

_PETROL_QTYPE = "Petrol"

Expand Down
7 changes: 5 additions & 2 deletions queries/places.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
AnswerTuple,
read_grammar_file,
)
from speech.trans import gssml
from icespeak import gssml
from tree import Result, Node


Expand All @@ -76,7 +76,10 @@ def help_text(lemma: str) -> str:
one of the above lemmas is found in it"""
return "Ég get svarað ef þú spyrð til dæmis: {0}?".format(
random.choice(
("Hvað er opið lengi á Forréttabarnum", "Hvenær lokar Bónus á Fiskislóð",)
(
"Hvað er opið lengi á Forréttabarnum",
"Hvenær lokar Bónus á Fiskislóð",
)
)
)

Expand Down
2 changes: 1 addition & 1 deletion queries/rand.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from queries import Query, QueryStateDict, AnswerTuple
from queries.util import gen_answer, read_grammar_file
from queries.arithmetic import add_num, terminal_num
from speech.trans import gssml
from icespeak import gssml
from tree import Result, Node


Expand Down
2 changes: 1 addition & 1 deletion queries/schedules.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

from tokenizer import split_into_sentences

from speech.trans import gssml
from icespeak import gssml
from settings import changedlocale
from queries.util import query_json_api, read_grammar_file

Expand Down
2 changes: 1 addition & 1 deletion queries/special.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from utility import icequote

from queries import Query
from speech.trans import gssml
from icespeak import gssml

# Type definitions
AnswerEntry = Union[str, bool]
Expand Down
2 changes: 1 addition & 1 deletion queries/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
from queries import Query
from queries.util import gen_answer, natlang_seq, is_plural, iceformat_float
from routes.people import top_persons
from speech.trans import gssml
from icespeak import gssml

_STATS_QTYPE = "Stats"

Expand Down
3 changes: 1 addition & 2 deletions queries/sunpos.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
ICE_PLACENAME_BLACKLIST,
)
from iceaddr import placename_lookup
from speech.trans.num import numbers_to_ordinal, floats_to_text
from icespeak.transcribe.num import numbers_to_ordinal, floats_to_text

# Indicate that this module wants to handle parse trees for queries,
# as opposed to simple literal text strings
Expand Down Expand Up @@ -495,7 +495,6 @@ def _answer_city_solar_data(


def _get_answer(q: Query, result: Result) -> AnswerTuple:

qdate: datetime.date = result.get("date", datetime.date.today())
sun_pos: int = result.get("solar_position")

Expand Down
2 changes: 1 addition & 1 deletion queries/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
)
from queries import Query
from queries.util import timezone4loc, gen_answer
from speech.trans import gssml
from icespeak import gssml
from utility import icequote

_TIME_QTYPE = "Time"
Expand Down
2 changes: 1 addition & 1 deletion queries/unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from queries import Query, QueryStateDict, to_dative, to_accusative
from queries.util import iceformat_float, parse_num, read_grammar_file, is_plural
from tree import Result, Node
from speech.trans import gssml
from icespeak import gssml

# Lemmas of keywords that could indicate that the user is trying to use this module
TOPIC_LEMMAS = [
Expand Down
10 changes: 5 additions & 5 deletions queries/userinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
from geo import icelandic_addr_info, iceprep_for_placename, iceprep_for_street
from queries import ClientDataDict, Query
from queries.util import gen_answer
from speech.trans.num import numbers_to_text
from icespeak.transcribe.num import numbers_to_text


_USERINFO_QTYPE = "UserInfo"
Expand Down Expand Up @@ -328,18 +328,18 @@ def _myaddris_handler(q: Query, ql: str) -> bool:
return True


#def _whatsmynum_handler(q: Query, ql: str) -> bool:
# def _whatsmynum_handler(q: Query, ql: str) -> bool:
# """Handle queries of the form "Hvað er símanúmerið mitt?"""
# return False
#
#_MY_PHONE_IS_REGEXES = (
# _MY_PHONE_IS_REGEXES = (
# r"símanúmer mitt er (.+)$",
# r"símanúmerið mitt er (.+)$",
# r"ég er með símanúmer (.+)$",
# r"ég er með símanúmerið (.+)$",
#)
# )
#
#_DUNNO_PHONE_NUM = "Ég veit ekki hvert símanúmer þitt er, en þú getur sagt mér það."
# _DUNNO_PHONE_NUM = "Ég veit ekki hvert símanúmer þitt er, en þú getur sagt mér það."


_DEVICE_TYPE_QUERIES = frozenset(
Expand Down
2 changes: 1 addition & 1 deletion queries/userloc.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
nom2dat,
read_grammar_file,
)
from speech.trans.num import numbers_to_text
from icespeak.transcribe.num import numbers_to_text
from tree import Result, Node
from iceaddr import iceaddr_lookup, postcodes
from geo import (
Expand Down
2 changes: 1 addition & 1 deletion queries/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
from pytz import country_timezones

from geo import country_name_for_isocode, iceprep_for_cc, LatLonTuple
from speech.trans.num import number_to_text, float_to_text
from icespeak.transcribe.num import number_to_text, float_to_text
from reynir import NounPhrase
from tree import Node
from settings import changedlocale
Expand Down
10 changes: 7 additions & 3 deletions queries/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
from iceaddr import placename_lookup # type: ignore
from iceweather import observation_for_closest, observation_for_station, forecast_text # type: ignore

from speech.trans import gssml
from icespeak import gssml

_WEATHER_QTYPE = "Weather"

Expand Down Expand Up @@ -351,9 +351,13 @@ def get_currweather_answer(query: Query, result: Result) -> AnswerTuple:
return response, answer, voice


def gpt_query(q: Query, query: str, time: str, location: str) -> Dict[str, Union[str, int, float]]:
def gpt_query(
q: Query, query: str, time: str, location: str
) -> Dict[str, Union[str, int, float]]:
"""Return a string response for a GPT query"""
weather: Dict[str, Union[str, int, float]] = dict(temperature=random.randint(-10, 30), wind=random.randint(0, 20))
weather: Dict[str, Union[str, int, float]] = dict(
temperature=random.randint(-10, 30), wind=random.randint(0, 20)
)
return weather


Expand Down
2 changes: 1 addition & 1 deletion queries/wiki.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

from tree import Result, Node
from utility import cap_first
from speech.trans import gssml
from icespeak import gssml
from queries import Query, QueryStateDict, ContextDict
from queries.util import query_json_api, gen_answer, read_grammar_file

Expand Down
2 changes: 1 addition & 1 deletion queries/words.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
from queries import Query, AnswerTuple
from queries.util import gen_answer
from utility import icequote
from speech.trans import gssml
from icespeak import gssml


_WORDTYPE_RX_NOM = "(?:orðið|nafnið|nafnorðið)"
Expand Down
2 changes: 1 addition & 1 deletion queries/yulelads.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from queries import Query, QueryStateDict
from tree import Result, Node, TerminalNode
from queries.util import read_grammar_file
from speech.trans.num import numbers_to_ordinal
from icespeak.transcribe.num import numbers_to_ordinal


def help_text(lemma: str) -> str:
Expand Down
8 changes: 1 addition & 7 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,12 @@ timezonefinder>=6.2.0
rjsmin>=1.2.1
python-youtube>=0.9.0
country-list>=1.0.0
# AWS Polly text-to-speech
botocore==1.21.40
boto3==1.18.40
# Azure text-to-speech.
azure-cognitiveservices-speech>=1.28.0
# Google text-to-speech
# google-cloud-texttospeech>=2.14.1
# For OpenAI GPT support
openai>=0.27.6
# Ours
reynir>=3.5.4
islenska>=0.4.8
icespeak>=0.3.2
iceaddr>=0.5.5
iceweather>=0.2.3
cityloc>=0.1.1
Expand Down
Loading

0 comments on commit a87a4bd

Please sign in to comment.