sonusai 0.18.1__py3-none-any.whl → 0.18.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
sonusai/mixture/mixdb.py CHANGED
@@ -4,7 +4,6 @@ from functools import partial
4
4
  from sqlite3 import Connection
5
5
  from sqlite3 import Cursor
6
6
  from typing import Any
7
- from typing import Callable
8
7
  from typing import Optional
9
8
 
10
9
  from sonusai.mixture.datatypes import AudioF
@@ -1062,13 +1061,13 @@ class MixtureDatabase:
1062
1061
 
1063
1062
  def mixids_for_speech_metadata(self,
1064
1063
  tier: str,
1065
- value: str | None,
1066
- predicate: Callable[[str], bool] = None) -> list[int]:
1064
+ value: str = None,
1065
+ where: str = None) -> list[int]:
1067
1066
  """Get a list of mixture IDs for the given speech metadata tier.
1068
1067
 
1069
- If 'predicate' is None, then include mixture IDs whose tier values are equal to the given 'value'.
1070
- If 'predicate' is not None, then ignore 'value' and use the given callable to determine which entries
1071
- to include.
1068
+ If 'where' is None, then include mixture IDs whose tier values are equal to the given 'value'.
1069
+ If 'where' is not None, then ignore 'value' and use the given SQL where clause to determine
1070
+ which entries to include.
1072
1071
 
1073
1072
  Examples:
1074
1073
  >>> mixdb = MixtureDatabase('/mixdb_location')
@@ -1076,35 +1075,33 @@ class MixtureDatabase:
1076
1075
  >>> mixids = mixdb.mixids_for_speech_metadata('speaker_id', 'TIMIT_ARC0')
1077
1076
  Get mixutre IDs for mixtures with speakers whose speaker_ids are 'TIMIT_ARC0'.
1078
1077
 
1079
- >>> mixids = mixdb.mixids_for_speech_metadata('age', '', lambda x: int(x) < 25)
1078
+ >>> mixids = mixdb.mixids_for_speech_metadata('age', where='age < 25')
1080
1079
  Get mixture IDs for mixtures with speakers whose ages are less than 25.
1081
1080
 
1082
- >>> mixids = mixdb.mixids_for_speech_metadata('dialect', '', lambda x: x in ['New York City', 'Northern'])
1081
+ >>> mixids = mixdb.mixids_for_speech_metadata('dialect', where="dialect in ('New York City', 'Northern')")
1083
1082
  Get mixture IDs for mixtures with speakers whose dialects are either 'New York City' or 'Northern'.
1084
1083
  """
1085
- from .helpers import get_textgrid_tier_from_target_file
1084
+ from sonusai import SonusAIError
1086
1085
 
1087
- if predicate is None:
1088
- def predicate(x: str | None) -> bool:
1089
- return x == value
1086
+ if value is None and where is None:
1087
+ raise SonusAIError('Must provide either value or where')
1090
1088
 
1091
- # First get list of matching target files
1092
- target_file_ids: list[int] = []
1093
- is_textgrid = tier in self.textgrid_metadata_tiers
1094
- for target_file_id, target_file in enumerate(self.target_files):
1095
- if is_textgrid:
1096
- metadata = get_textgrid_tier_from_target_file(target_file.name, tier)
1097
- else:
1098
- metadata = self.speaker(target_file.speaker_id, tier)
1089
+ if where is None:
1090
+ where = f"{tier} = '{value}'"
1099
1091
 
1100
- if not isinstance(metadata, list) and predicate(metadata):
1101
- target_file_ids.append(target_file_id + 1)
1092
+ if tier in self.textgrid_metadata_tiers:
1093
+ raise SonusAIError(f'TextGrid tier data, "{tier}", is not supported in mixids_for_speech_metadata().')
1102
1094
 
1103
- # Next get list of mixture IDs that contain those target files
1104
1095
  with self.db() as c:
1105
- m_ids = c.execute("SELECT mixture_id FROM mixture_target " +
1106
- f"WHERE mixture_target.target_id IN ({','.join(map(str, target_file_ids))})").fetchall()
1107
- return [x[0] - 1 for x in m_ids]
1096
+ speaker_ids = [speaker_id[0] for speaker_id in
1097
+ c.execute(f"SELECT id FROM speaker WHERE {where}").fetchall()]
1098
+ results = c.execute(f"SELECT id FROM target_file " +
1099
+ f"WHERE speaker_id IN ({','.join(map(str, speaker_ids))})").fetchall()
1100
+ target_file_ids = [target_file_id[0] for target_file_id in results]
1101
+ results = c.execute("SELECT mixture_id FROM mixture_target " +
1102
+ f"WHERE mixture_target.target_id IN ({','.join(map(str, target_file_ids))})").fetchall()
1103
+
1104
+ return [mixture_id[0] - 1 for mixture_id in results]
1108
1105
 
1109
1106
  def mixture_all_speech_metadata(self, m_id: int) -> list[dict[str, SpeechMetadata]]:
1110
1107
  from .helpers import mixture_all_speech_metadata
@@ -1160,7 +1157,7 @@ class MixtureDatabase:
1160
1157
  )
1161
1158
 
1162
1159
  if not (metric in supported_metrics or metric.startswith('MXWER')):
1163
- raise ValueError(f'Unsupported metric: {metric}')
1160
+ raise SonusAIError(f'Unsupported metric: {metric}')
1164
1161
 
1165
1162
  if not force:
1166
1163
  result = self.read_mixture_data(m_id, metric)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sonusai
3
- Version: 0.18.1
3
+ Version: 0.18.2
4
4
  Summary: Framework for building deep neural network models for sound, speech, and voice AI
5
5
  Home-page: https://aaware.com
6
6
  License: GPL-3.0-only
@@ -43,7 +43,7 @@ sonusai/mixture/generation.py,sha256=ohZnhtHIrdQDql2OF703NnhK07Ys-1qAjiwrIql-oMw
43
43
  sonusai/mixture/helpers.py,sha256=eC9ZysEa-83VLKen_9PKWzr8w9dkHj4lp6rMB2fNLbg,24759
44
44
  sonusai/mixture/log_duration_and_sizes.py,sha256=baTUpqyM15wA125jo9E3posmVJUe3WlpksyO6v9Jul0,1347
45
45
  sonusai/mixture/mapped_snr_f.py,sha256=Fdf2uw62FvyKvVy5VywaUtPZGO1zCWQsHlte0bwkKPQ,3121
46
- sonusai/mixture/mixdb.py,sha256=XSJQKYaUfQylpWbGjfxfP7dendr-9JFcmLWNyE0qUwQ,51697
46
+ sonusai/mixture/mixdb.py,sha256=s40-NToxNXz3UtiVZW9chHIV-tpqT6u-GbFPg8LfQoc,51644
47
47
  sonusai/mixture/soundfile_audio.py,sha256=mHa5SIXsu_uE0j3DO52GydRJrvWSzU_nII-7YJfQ6Qo,4154
48
48
  sonusai/mixture/sox_audio.py,sha256=HT3kYA9TP5QPCuoOJdUMnGVN-qY6q96DGL8zxuog76o,12277
49
49
  sonusai/mixture/sox_augmentation.py,sha256=kBWPrsFk0EBi71nLcKt5v0GA34bY7g9D9x0cEamNWbU,4564
@@ -116,7 +116,7 @@ sonusai/utils/stratified_shuffle_split.py,sha256=rJNXvBp-GxoKzH3OpL7k0ANSu5xMP2z
116
116
  sonusai/utils/write_audio.py,sha256=ZsPGExwM86QHLLN2LOWekK2uAqf5pV_1oRW811p0QAI,840
117
117
  sonusai/utils/yes_or_no.py,sha256=eMLXBVH0cEahiXY4W2KNORmwNQ-ba10eRtldh0y4NYg,263
118
118
  sonusai/vars.py,sha256=m2AefF0m5bXWGXpJj8Pi42zWL2ydeEj7bkak3GrtMyM,940
119
- sonusai-0.18.1.dist-info/METADATA,sha256=cLhSYAb5FSCHlrBCG0xA2hwa_4S86JUEWIqY85xA5o8,2591
120
- sonusai-0.18.1.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
121
- sonusai-0.18.1.dist-info/entry_points.txt,sha256=zMNjEphEPO6B3cD1GNpit7z-yA9tUU5-j3W2v-UWstU,92
122
- sonusai-0.18.1.dist-info/RECORD,,
119
+ sonusai-0.18.2.dist-info/METADATA,sha256=PNDYtM4HDRWpp3GBcuos7jymdaKRoXOT7DlLn-fs8XE,2591
120
+ sonusai-0.18.2.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
121
+ sonusai-0.18.2.dist-info/entry_points.txt,sha256=zMNjEphEPO6B3cD1GNpit7z-yA9tUU5-j3W2v-UWstU,92
122
+ sonusai-0.18.2.dist-info/RECORD,,