HarmanpreetKaur commited on
Commit
3c63367
·
1 Parent(s): 915c65a

Files updated

Browse files
__pycache__/.env ADDED
@@ -0,0 +1 @@
 
 
1
+ DEEPGRAM_API_KEY = "5da1cbb9a0b27337e1ae7dc141b48c6775912ed2"
__pycache__/speechtotext.cpython-310.pyc ADDED
Binary file (1.22 kB). View file
 
__pycache__/speechtotext.cpython-38.pyc ADDED
Binary file (1.36 kB). View file
 
__pycache__/t2s.cpython-310.pyc ADDED
Binary file (988 Bytes). View file
 
__pycache__/t2s.cpython-38.pyc ADDED
Binary file (833 Bytes). View file
 
__pycache__/transcript.cpython-310.pyc ADDED
Binary file (1 kB). View file
 
__pycache__/transcript.cpython-38.pyc ADDED
Binary file (1.43 kB). View file
 
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from speechtotext import speech_to_text
3
+ from t2s import text_to_speech_page
4
+
5
+ def main():
6
+ st.title("Speak n Text")
7
+
8
+ # Define a dictionary to map page names to their corresponding functions
9
+ pages = {
10
+ "Text to Speech": text_to_speech_page,
11
+ "Speech to Text": speech_to_text
12
+ }
13
+
14
+ # Display a sidebar for navigation
15
+ st.sidebar.title("Navigation")
16
+
17
+ # Get the selection from the user
18
+ selection = st.sidebar.radio("Go to", list(pages.keys()))
19
+
20
+ # If the user selects "Text to Speech", show the text-to-speech page
21
+ if selection == "Text to Speech":
22
+ text_to_speech_page()
23
+
24
+ # If the user selects "Speech to Text", show the speech-to-text page
25
+ elif selection == "Speech to Text":
26
+ speech_to_text()
27
+
28
+ # Add additional pages here as needed
29
+ # elif selection == "Page Name":
30
+ # page_function()
31
+
32
+ if __name__ == "__main__":
33
+ main()
output.mp3 ADDED
Binary file (16.3 kB). View file
 
speechtotext.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from deepgram import Deepgram
3
+ from transcript import deepgram
4
+ import urllib3
5
+ urllib3.disable_warnings()
6
+
7
+ def speech_to_text():
8
+ st.title("Speech to Text")
9
+
10
+ # File uploader for audio files
11
+ uploaded_file = st.sidebar.file_uploader("Upload Audio File", type=["wav", "mp3"])
12
+
13
+ if uploaded_file is not None:
14
+ st.sidebar.audio(uploaded_file, format='audio/wav/mp3') # Display the uploaded audio file
15
+ st.spinner("Uploading in progress....")
16
+
17
+ # Language selection dropdown
18
+ options = st.sidebar.selectbox("Select Language", ["English","Hindi"])
19
+ if options=='English':
20
+ language="en"
21
+ elif options=='Hindi':
22
+ language="hi"
23
+
24
+
25
+
26
+ # Button to trigger transcription
27
+ if st.sidebar.button("Transcribe"):
28
+ with st.spinner("Please Wait,Transcribing in progress..."):
29
+ # Call the transcribe_audio function
30
+ transcript = deepgram(uploaded_file, language)
31
+ with st.container(height=500):
32
+ st.markdown(transcript)
33
+
34
+ st.download_button(
35
+ label="Download Transcribed Text",
36
+ data=transcript,
37
+ file_name="transcribed_text.txt",
38
+ mime="text/plain"
39
+ )
40
+
41
+
42
+
43
+
44
+ if __name__ == "__main__":
45
+ speech_to_text()
46
+
47
+
t2s.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from gtts import gTTS
3
+ import os
4
+
5
+ # Function to save the speech to a file using gTTS
6
+ def save_speech(text, lang, filename):
7
+ tts = gTTS(text=text, lang=lang)
8
+ tts.save(filename)
9
+
10
+ # Function to run the Streamlit app
11
+ def text_to_speech_page():
12
+ st.title("Text-to-Speech")
13
+
14
+ # Dropdown to select language
15
+ language = st.selectbox("Select Language", ["English", "Hindi"])
16
+
17
+ # Text input for the user to enter text
18
+ text_input = st.text_area("Enter text to convert to speech", "")
19
+
20
+ # Button to trigger TTS
21
+ if st.button("Convert to Speech"):
22
+ if text_input:
23
+ # Map the selected language to gTTS language codes
24
+ lang_code = 'en'
25
+ if language == "Hindi":
26
+ lang_code = 'hi'
27
+
28
+
29
+ # Save the speech to an audio file
30
+ output_audio_file = "output.mp3"
31
+ save_speech(text_input, lang_code, output_audio_file)
32
+
33
+ # Play the audio file
34
+ st.audio(output_audio_file, format='audio/mp3')
35
+ else:
36
+ st.warning("Please enter some text to convert.")
37
+
38
+ # Run the app
39
+ if __name__ == "__main__":
40
+ text_to_speech_page()
transcript.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ from deepgram import (
3
+ DeepgramClient,
4
+ PrerecordedOptions,
5
+ FileSource
6
+ )
7
+ import httpx
8
+ from sumy.parsers.plaintext import PlaintextParser
9
+ from sumy.nlp.tokenizers import Tokenizer
10
+ from sumy.summarizers.lsa import LsaSummarizer
11
+
12
+ def deepgram(buffer_data,language):
13
+ # STEP 1 Create a Deepgram client using the API key
14
+ deepgram = DeepgramClient('5da1cbb9a0b27337e1ae7dc141b48c6775912ed2')
15
+
16
+ payload: FileSource = {
17
+ "buffer": buffer_data,
18
+ }
19
+
20
+ #STEP 2: Configure Deepgram options for audio analysis
21
+ options = PrerecordedOptions(
22
+ model="nova-2",
23
+ smart_format=True,
24
+ language=language,
25
+ diarize=True
26
+
27
+ )
28
+ myTimeout = httpx.Timeout(timeout=300, connect=10.0)
29
+
30
+ # STEP 3: Call the transcribe_file method with the text payload and options
31
+ response = deepgram.listen.prerecorded.v("1").transcribe_file(payload, options,timeout=myTimeout)
32
+ text=response['results']['channels'][0]['alternatives'][0]['paragraphs']['transcript']
33
+ return text
34
+
transcription.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ Speaker 0: Learn English intensely learn English faster by
3
+
4
+ Speaker 1: practicing intense immersion. While it's fine to learn slowly sometimes, you can make tremendous progress by studying intensely for 1 month. Intensity focuses your brain and immerses it in English you'll learn more you'll remember more you'll speak better and you'll feel more confident if you study English intensely for 1 full month. Do this 3 to 5 times a year. How should you study intensely?
5
+
6
+ I recommend 4 or more hours a day of English study. You should divide this time over the entire day so for example listen 1 hour in the morning 1 hour during lunch, 1 hour going home from work, and 1 hour before sleep. Here's the plan I recommend. Number 1, listen to the lessons for 2 hours each day during your intensity month. Focus especially on the main audio articles and on the mini story and POV lessons.
7
+
8
+ These are the most powerful lessons and they are the most important. If you spend 2 hours every day focused on these lessons, your speaking and understanding will improve very quickly. Number 2, listen for 1 hour a day to a movie. Use my movie technique. Study only one scene for 3 to 7 days.
9
+
10
+ 1st, use the subtitles to understand the vocabulary and meaning. Then, listen and use subtitles at the same time finally, turn off the subtitles and listen to the scene many times. And number 3, read an easy novel, 1 hour every day. I recommend children's novels to start with. Then you can gradually find more difficult books.
11
+
12
+ You should not need a dictionary to understand the book. If you need a dictionary, it's too difficult, so find an easier book. By following the above plan for 30 days or more, you will create a sudden, big, powerful improvement in your English ability. Your listening and speaking will show a huge improvement. Your vocabulary will grow quickly you'll feel more confident when you speak you don't always need to follow this plan but try to use it for just 30 days.
13
+
14
+ Do these intense study months every 2 or 3 months and you will get amazing results.