Olaolu Olugbenle commited on
Commit
10b4ef5
·
1 Parent(s): bb6033f

python file used for testing translator

Browse files
Files changed (1) hide show
  1. test.py +93 -0
test.py CHANGED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from google.cloud.speech_v2 import SpeechClient
2
+ from google.cloud.speech_v2.types import cloud_speech
3
+ import os
4
+ import base64
5
+ import tempfile
6
+ from dotenv import load_dotenv
7
+
8
+ # # TODO(developer): Update and un-comment below line
9
+ # PROJECT_ID = "perfect-spanner-475822-p6"
10
+
11
+ load_dotenv()
12
+
13
+ # # Load and decode Google credentials (Base64 Encoding)
14
+ # creds_b64 = os.getenv("GOOGLE_APPLICATION_CREDENTIALS_JSON") #get the b64 string
15
+ # if creds_b64:
16
+ # creds_json = base64.b64decode(creds_b64).decode("utf-8") #decode to json string
17
+ # temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".json") #create a temp file
18
+ # temp_file.write(creds_json.encode("utf-8")) #write json to this file
19
+ # temp_file.flush() #write
20
+ # os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = temp_file.name #update cred
21
+ # else:
22
+ # print("⚠️ No GCP creds found.")
23
+
24
+ # # Instantiates a client
25
+ # client = SpeechClient()
26
+
27
+ # # Reads a file as bytes
28
+ # with open("yoruba-practice/audio.m4a", "rb") as f:
29
+ # audio_content = f.read()
30
+
31
+ # config = cloud_speech.RecognitionConfig(
32
+ # auto_decoding_config=cloud_speech.AutoDetectDecodingConfig(),
33
+ # language_codes=["en-US"],
34
+ # model="chirp_3",
35
+ # )
36
+
37
+ # request = cloud_speech.RecognizeRequest(
38
+ # recognizer=f"projects/{PROJECT_ID}/locations/global/recognizers/_",
39
+ # config=config,
40
+ # content=audio_content,
41
+ # )
42
+
43
+ # # Transcribes the audio into text
44
+ # response = client.recognize(request=request)
45
+
46
+ # for result in response.results:
47
+ # print(f"Transcript: {result.alternatives[0].transcript}")
48
+
49
+
50
+
51
+ #SPITCH TEST
52
+ import os
53
+ from spitch import Spitch
54
+
55
+ client = Spitch()
56
+
57
+ with open("new.mp3", "wb") as f:
58
+ response = client.speech.generate(
59
+ text="Oya, no dey do dat kind tin o. I no get time to waste. Johnny my son, I send you to school to learn how to spell your name",
60
+ language="en",
61
+ voice="jude",
62
+ format="mp3"
63
+ )
64
+ f.write(response.read())
65
+
66
+
67
+
68
+ #Yarn GPT TTS TEST
69
+ import requests
70
+
71
+
72
+ API_URL = "https://yarngpt.ai/api/v1/tts"
73
+ API_KEY = os.getenv("YARNGPT_API_KEY")
74
+
75
+ headers = {
76
+ "Authorization": f"Bearer {API_KEY}"
77
+ }
78
+
79
+ payload = {
80
+ "text": "Ẹ káàárọ̀ ọ̀rẹ́ mi. Mo fẹ́ ra ẹ̀wà.",
81
+ "voice": "Idera",
82
+ }
83
+
84
+ response = requests.post(API_URL, headers=headers, json=payload, stream=True)
85
+
86
+ if response.status_code == 200:
87
+ with open("output.mp3", "wb") as f:
88
+ for chunk in response.iter_content(chunk_size=8192):
89
+ f.write(chunk)
90
+ print("Audio file saved as output.mp3")
91
+ else:
92
+ print(f"Error: {response.status_code}")
93
+ print(response.json())