webscout 1.3.5__py3-none-any.whl → 1.3.8__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.

Potentially problematic release.


This version of webscout might be problematic. Click here for more details.

webscout/AIutel.py CHANGED
@@ -11,6 +11,13 @@ import click
11
11
  from rich.markdown import Markdown
12
12
  from rich.console import Console
13
13
  import g4f
14
+ from typing import Union
15
+ from typing import NoReturn
16
+ import requests
17
+ from pathlib import Path
18
+ from playsound import playsound
19
+ from time import sleep as wait
20
+ import pathlib
14
21
  appdir = appdirs.AppDirs("AIWEBS", "vortex")
15
22
 
16
23
  default_path = appdir.user_cache_dir
@@ -29,6 +36,8 @@ webai = [
29
36
  "perplexity",
30
37
  "sean",
31
38
  "groq",
39
+ "reka",
40
+ "cohere"
32
41
  ]
33
42
 
34
43
  gpt4free_providers = [
@@ -669,4 +678,294 @@ Current Datetime : {datetime.datetime.now()}
669
678
  f"{e.args[1] if len(e.args)>1 else str(e)}",
670
679
  "error",
671
680
  )
672
- return f"PREVIOUS SCRIPT EXCEPTION:\n{str(e)}"
681
+ return f"PREVIOUS SCRIPT EXCEPTION:\n{str(e)}"
682
+ class Audio:
683
+ # Request headers
684
+ headers: dict[str, str] = {
685
+ "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36"
686
+ }
687
+ cache_dir = pathlib.Path("./audio_cache")
688
+ all_voices: list[str] = [
689
+ "Filiz",
690
+ "Astrid",
691
+ "Tatyana",
692
+ "Maxim",
693
+ "Carmen",
694
+ "Ines",
695
+ "Cristiano",
696
+ "Vitoria",
697
+ "Ricardo",
698
+ "Maja",
699
+ "Jan",
700
+ "Jacek",
701
+ "Ewa",
702
+ "Ruben",
703
+ "Lotte",
704
+ "Liv",
705
+ "Seoyeon",
706
+ "Takumi",
707
+ "Mizuki",
708
+ "Giorgio",
709
+ "Carla",
710
+ "Bianca",
711
+ "Karl",
712
+ "Dora",
713
+ "Mathieu",
714
+ "Celine",
715
+ "Chantal",
716
+ "Penelope",
717
+ "Miguel",
718
+ "Mia",
719
+ "Enrique",
720
+ "Conchita",
721
+ "Geraint",
722
+ "Salli",
723
+ "Matthew",
724
+ "Kimberly",
725
+ "Kendra",
726
+ "Justin",
727
+ "Joey",
728
+ "Joanna",
729
+ "Ivy",
730
+ "Raveena",
731
+ "Aditi",
732
+ "Emma",
733
+ "Brian",
734
+ "Amy",
735
+ "Russell",
736
+ "Nicole",
737
+ "Vicki",
738
+ "Marlene",
739
+ "Hans",
740
+ "Naja",
741
+ "Mads",
742
+ "Gwyneth",
743
+ "Zhiyu",
744
+ "es-ES-Standard-A",
745
+ "it-IT-Standard-A",
746
+ "it-IT-Wavenet-A",
747
+ "ja-JP-Standard-A",
748
+ "ja-JP-Wavenet-A",
749
+ "ko-KR-Standard-A",
750
+ "ko-KR-Wavenet-A",
751
+ "pt-BR-Standard-A",
752
+ "tr-TR-Standard-A",
753
+ "sv-SE-Standard-A",
754
+ "nl-NL-Standard-A",
755
+ "nl-NL-Wavenet-A",
756
+ "en-US-Wavenet-A",
757
+ "en-US-Wavenet-B",
758
+ "en-US-Wavenet-C",
759
+ "en-US-Wavenet-D",
760
+ "en-US-Wavenet-E",
761
+ "en-US-Wavenet-F",
762
+ "en-GB-Standard-A",
763
+ "en-GB-Standard-B",
764
+ "en-GB-Standard-C",
765
+ "en-GB-Standard-D",
766
+ "en-GB-Wavenet-A",
767
+ "en-GB-Wavenet-B",
768
+ "en-GB-Wavenet-C",
769
+ "en-GB-Wavenet-D",
770
+ "en-US-Standard-B",
771
+ "en-US-Standard-C",
772
+ "en-US-Standard-D",
773
+ "en-US-Standard-E",
774
+ "de-DE-Standard-A",
775
+ "de-DE-Standard-B",
776
+ "de-DE-Wavenet-A",
777
+ "de-DE-Wavenet-B",
778
+ "de-DE-Wavenet-C",
779
+ "de-DE-Wavenet-D",
780
+ "en-AU-Standard-A",
781
+ "en-AU-Standard-B",
782
+ "en-AU-Wavenet-A",
783
+ "en-AU-Wavenet-B",
784
+ "en-AU-Wavenet-C",
785
+ "en-AU-Wavenet-D",
786
+ "en-AU-Standard-C",
787
+ "en-AU-Standard-D",
788
+ "fr-CA-Standard-A",
789
+ "fr-CA-Standard-B",
790
+ "fr-CA-Standard-C",
791
+ "fr-CA-Standard-D",
792
+ "fr-FR-Standard-C",
793
+ "fr-FR-Standard-D",
794
+ "fr-FR-Wavenet-A",
795
+ "fr-FR-Wavenet-B",
796
+ "fr-FR-Wavenet-C",
797
+ "fr-FR-Wavenet-D",
798
+ "da-DK-Wavenet-A",
799
+ "pl-PL-Wavenet-A",
800
+ "pl-PL-Wavenet-B",
801
+ "pl-PL-Wavenet-C",
802
+ "pl-PL-Wavenet-D",
803
+ "pt-PT-Wavenet-A",
804
+ "pt-PT-Wavenet-B",
805
+ "pt-PT-Wavenet-C",
806
+ "pt-PT-Wavenet-D",
807
+ "ru-RU-Wavenet-A",
808
+ "ru-RU-Wavenet-B",
809
+ "ru-RU-Wavenet-C",
810
+ "ru-RU-Wavenet-D",
811
+ "sk-SK-Wavenet-A",
812
+ "tr-TR-Wavenet-A",
813
+ "tr-TR-Wavenet-B",
814
+ "tr-TR-Wavenet-C",
815
+ "tr-TR-Wavenet-D",
816
+ "tr-TR-Wavenet-E",
817
+ "uk-UA-Wavenet-A",
818
+ "ar-XA-Wavenet-A",
819
+ "ar-XA-Wavenet-B",
820
+ "ar-XA-Wavenet-C",
821
+ "cs-CZ-Wavenet-A",
822
+ "nl-NL-Wavenet-B",
823
+ "nl-NL-Wavenet-C",
824
+ "nl-NL-Wavenet-D",
825
+ "nl-NL-Wavenet-E",
826
+ "en-IN-Wavenet-A",
827
+ "en-IN-Wavenet-B",
828
+ "en-IN-Wavenet-C",
829
+ "fil-PH-Wavenet-A",
830
+ "fi-FI-Wavenet-A",
831
+ "el-GR-Wavenet-A",
832
+ "hi-IN-Wavenet-A",
833
+ "hi-IN-Wavenet-B",
834
+ "hi-IN-Wavenet-C",
835
+ "hu-HU-Wavenet-A",
836
+ "id-ID-Wavenet-A",
837
+ "id-ID-Wavenet-B",
838
+ "id-ID-Wavenet-C",
839
+ "it-IT-Wavenet-B",
840
+ "it-IT-Wavenet-C",
841
+ "it-IT-Wavenet-D",
842
+ "ja-JP-Wavenet-B",
843
+ "ja-JP-Wavenet-C",
844
+ "ja-JP-Wavenet-D",
845
+ "cmn-CN-Wavenet-A",
846
+ "cmn-CN-Wavenet-B",
847
+ "cmn-CN-Wavenet-C",
848
+ "cmn-CN-Wavenet-D",
849
+ "nb-no-Wavenet-E",
850
+ "nb-no-Wavenet-A",
851
+ "nb-no-Wavenet-B",
852
+ "nb-no-Wavenet-C",
853
+ "nb-no-Wavenet-D",
854
+ "vi-VN-Wavenet-A",
855
+ "vi-VN-Wavenet-B",
856
+ "vi-VN-Wavenet-C",
857
+ "vi-VN-Wavenet-D",
858
+ "sr-rs-Standard-A",
859
+ "lv-lv-Standard-A",
860
+ "is-is-Standard-A",
861
+ "bg-bg-Standard-A",
862
+ "af-ZA-Standard-A",
863
+ "Tracy",
864
+ "Danny",
865
+ "Huihui",
866
+ "Yaoyao",
867
+ "Kangkang",
868
+ "HanHan",
869
+ "Zhiwei",
870
+ "Asaf",
871
+ "An",
872
+ "Stefanos",
873
+ "Filip",
874
+ "Ivan",
875
+ "Heidi",
876
+ "Herena",
877
+ "Kalpana",
878
+ "Hemant",
879
+ "Matej",
880
+ "Andika",
881
+ "Rizwan",
882
+ "Lado",
883
+ "Valluvar",
884
+ "Linda",
885
+ "Heather",
886
+ "Sean",
887
+ "Michael",
888
+ "Karsten",
889
+ "Guillaume",
890
+ "Pattara",
891
+ "Jakub",
892
+ "Szabolcs",
893
+ "Hoda",
894
+ "Naayf",
895
+ ]
896
+
897
+ @classmethod
898
+ def text_to_audio(
899
+ cls,
900
+ message: str,
901
+ voice: str = "Brian",
902
+ save_to: Union[Path, str] = None,
903
+ auto: bool = True,
904
+ ) -> Union[str, bytes]:
905
+ """
906
+ Text to speech using StreamElements API
907
+
908
+ Parameters:
909
+ message (str): The text to convert to speech
910
+ voice (str, optional): The voice to use for speech synthesis. Defaults to "Brian".
911
+ save_to (bool, optional): Path to save the audio file. Defaults to None.
912
+ auto (bool, optional): Generate filename based on `message` and save to `cls.cache_dir`. Defaults to False.
913
+
914
+ Returns:
915
+ result (Union[str, bytes]): Path to saved contents or audio content.
916
+ """
917
+ assert (
918
+ voice in cls.all_voices
919
+ ), f"Voice '{voice}' not one of [{', '.join(cls.all_voices)}]"
920
+ # Base URL for provider API
921
+ url: str = (
922
+ f"https://api.streamelements.com/kappa/v2/speech?voice={voice}&text={{{message}}}"
923
+ )
924
+ resp = requests.get(url=url, headers=cls.headers, stream=True)
925
+ if not resp.ok:
926
+ raise Exception(
927
+ f"Failed to perform the operation - ({resp.status_code}, {resp.reason}) - {resp.text}"
928
+ )
929
+
930
+ def sanitize_filename(path):
931
+ trash = [
932
+ "\\",
933
+ "/",
934
+ ":",
935
+ "*",
936
+ "?",
937
+ '"',
938
+ "<",
939
+ "|",
940
+ ">",
941
+ ]
942
+ for val in trash:
943
+ path = path.replace(val, "")
944
+ return path.strip()
945
+
946
+ if auto:
947
+ filename: str = message + "..." if len(message) <= 40 else message[:40]
948
+ save_to = cls.cache_dir / sanitize_filename(filename)
949
+ save_to = save_to.as_posix()
950
+
951
+ # Ensure cache_dir exists
952
+ cls.cache_dir.mkdir(parents=True, exist_ok=True)
953
+
954
+ if save_to:
955
+ if not save_to.endswith("mp3"):
956
+ save_to += ".mp3"
957
+
958
+ with open(save_to, "wb") as fh:
959
+ for chunk in resp.iter_content(chunk_size=512):
960
+ fh.write(chunk)
961
+ else:
962
+ return resp.content
963
+ return save_to
964
+
965
+ @staticmethod
966
+ def play(path_to_audio_file: Union[Path, str]) -> NoReturn:
967
+ """Play audio (.mp3) using playsound.
968
+ """
969
+ if not Path(path_to_audio_file).is_file():
970
+ raise FileNotFoundError(f"File does not exist - '{path_to_audio_file}'")
971
+ playsound(path_to_audio_file)
webscout/__init__.py CHANGED
@@ -26,6 +26,8 @@ webai = [
26
26
  "perplexity",
27
27
  "sean",
28
28
  "groq",
29
+ "reka",
30
+ "cohere"
29
31
  ]
30
32
 
31
33
  gpt4free_providers = [