Sukhmanpreet commited on
Commit
8b56adb
·
verified ·
1 Parent(s): cecae3e

Upload 6 files

Browse files
Files changed (6) hide show
  1. main.py +33 -0
  2. s2s.py +41 -0
  3. speechtotext.py +61 -0
  4. t2s.py +41 -0
  5. transcript.py +47 -0
  6. transcription.json +14 -0
main.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("VOICE TRANSFORMATION TECHNOLOGIES : EXPLORATION")
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()
s2s.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import speech_recognition as sr
2
+ import pyttsx3
3
+
4
+ # Function to transcribe audio to text
5
+ def transcribe_audio(audio_file):
6
+ recognizer = sr.Recognizer()
7
+ with sr.AudioFile(audio_file) as source:
8
+ audio_data = recognizer.record(source)
9
+ try:
10
+ text = recognizer.recognize_sphinx(audio_data)
11
+ return text
12
+ except sr.UnknownValueError:
13
+ return "Speech recognition could not understand audio"
14
+ except sr.RequestError as e:
15
+ return "Error with speech recognition service: {0}".format(e)
16
+
17
+ # Function to generate audio from text
18
+ def generate_audio(text, output_file, rate=150):
19
+ engine = pyttsx3.init()
20
+ engine.setProperty('rate', rate)
21
+ engine.save_to_file(text, output_file)
22
+ engine.runAndWait()
23
+
24
+ # Main code
25
+ if __name__ == "__main__":
26
+ # Example audio file (replace with your audio file)
27
+ audio_file = "input_audio.wav"
28
+
29
+ # Transcribe audio to text
30
+ transcribed_text = transcribe_audio(audio_file)
31
+
32
+ if transcribed_text:
33
+ print("Transcribed text:", transcribed_text)
34
+
35
+ # Generate audio from transcribed text
36
+ output_file = "output_audio.wav"
37
+ generate_audio(transcribed_text, output_file)
38
+
39
+ print("Audio generated successfully:", output_file)
40
+ else:
41
+ print("Failed to transcribe audio.")
speechtotext.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from deepgram import Deepgram
3
+ from transcript import deepgram
4
+ import requests
5
+ import urllib3
6
+ import base64
7
+ from transcript import summarize_text
8
+ urllib3.disable_warnings()
9
+
10
+ def speech_to_text():
11
+ st.title("Speech to Text")
12
+
13
+ # File uploader for audio files
14
+ uploaded_file = st.sidebar.file_uploader("Upload Audio File", type=["wav", "mp3"])
15
+
16
+ if uploaded_file is not None:
17
+ st.sidebar.audio(uploaded_file, format='audio/wav/mp3') # Display the uploaded audio file
18
+ st.spinner("Uploading in progress....")
19
+
20
+ # Language selection dropdown
21
+ options = st.sidebar.selectbox("Select Language", ["English","Hindi"])
22
+ if options=='English':
23
+ language="en"
24
+ elif options=='Hindi':
25
+ language="hi"
26
+
27
+
28
+
29
+ # Button to trigger transcription
30
+ if st.sidebar.button("Transcribe"):
31
+ with st.spinner("Please Wait,Transcribing in progress..."):
32
+ # Call the transcribe_audio function
33
+ transcript = deepgram(uploaded_file, language)
34
+ with st.container(height=500):
35
+ st.markdown(transcript)
36
+
37
+ st.download_button(
38
+ label="Download Transcribed Text",
39
+ data=transcript,
40
+ file_name="transcribed_text.txt",
41
+ mime="text/plain"
42
+ )
43
+
44
+
45
+ # Summarize transcription
46
+ summary = summarize_text(transcript)
47
+
48
+ # Display summary
49
+ st.subheader("Summary:")
50
+ st.write(summary)
51
+ st.download_button(
52
+ label="Download Summary",
53
+ data=summary,
54
+ file_name="summary.txt",
55
+ mime="text/plain",
56
+
57
+ )
58
+ if __name__ == "__main__":
59
+ speech_to_text()
60
+
61
+
t2s.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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", "Punjabi"])
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
+ elif language == "Punjabi":
28
+ lang_code = 'pa'
29
+
30
+ # Save the speech to an audio file
31
+ output_audio_file = "output.mp3"
32
+ save_speech(text_input, lang_code, output_audio_file)
33
+
34
+ # Play the audio file
35
+ st.audio(output_audio_file, format='audio/mp3')
36
+ else:
37
+ st.warning("Please enter some text to convert.")
38
+
39
+ # Run the app
40
+ if __name__ == "__main__":
41
+ text_to_speech_page()
transcript.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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(300, connect=10.0)
29
+ # STEP 3: Call the transcribe_file method with the text payload and options
30
+ response = deepgram.listen.prerecorded.v("1").transcribe_file(payload, options,timeout=myTimeout)
31
+ text=response['results']['channels'][0]['alternatives'][0]['paragraphs']['transcript']
32
+ return text
33
+
34
+ def summarize_text(text):
35
+ # Initialize parser
36
+ parser = PlaintextParser.from_string(text, Tokenizer("english"))
37
+
38
+ # Initialize LSA Summarizer
39
+ summarizer = LsaSummarizer()
40
+
41
+ # Summarize the document with 3 sentences
42
+ summary = summarizer(parser.document, 3)
43
+
44
+ # Convert summary sentences to string
45
+ summary_text = " ".join([str(sentence) for sentence in summary])
46
+
47
+ return summary_text
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.